We define a map as a set of key-value pairs. For this challenge, you need to take each of the values and assign them to a randomly chosen key.
- You must randomly shuffle the values, and output the resulting map. This means that each time we run your program, we have a chance of getting a different output
- Each possible permutation of the values must have a non-zero chance of appearing.
- All of the original keys and original values must appear in the resulting array. Repeated values must appear the same number of times in the resulting array.
For example, if your map was:
[0:10, 1:10, 5:5]
all of the following must have a chance of appearing:
[0:10, 1:10, 5:5] (original map)
[0:10, 1:5, 5:10]
[0:10, 1:10, 5:5] (technically the same map, but I swapped the two tens)
[0:10, 1:5, 5:10]
[0:5, 1:10, 5:10]
[0:5, 1:10, 5:10]
Acceptable input/outputs:
- Your languages' native map
- You can input an array of key-value pairs. You may not input 2 arrays, one with keys, the other with values.
- You can use a string representation of any the above
- If you input an array or a map, you can modify the original object instead of returning
- The input type must match the output type
- If you input an array, the order of the keys must be maintained.
- You can assume that the keys are unique, but you cannot assume that values are unique.
This is a code-golf, so answer as short as possible
[k, v]
or would[v, k]
be acceptable? \$\endgroup\$[k, v]
\$\endgroup\$