Shuffle
Shuffle
Shuffle[ list ] returns a copy of a list in a random order.
Usages
Shuffle[ list ]
Shuffle[ list ] returns a new list with the same elements as list, in a random order. Every element is kept, including duplicates. The original list is not changed. Each time the exercise is generated, a new order is chosen, so the outputs below are only examples.
| Example | in | out |
|---|---|---|
A shuffled copy of {3,4,5}. |
Shuffle[ {3,4,5} ] |
for example {5, 3, 4} |
| Duplicates are kept. | Shuffle[ {a,a,b} ] |
for example {a, b, a} |
A list stored in a script variable. The variable L itself is unchanged. |
L := {1,2,3,4} |
for example r = {1, 3, 4, 2} |
Details
- Empty list:
Shuffle[ {} ]returns{}. - The shuffled list can be the same as the original list, especially for short lists.
| Invalid input | Result |
|---|---|
Shuffle[ 5 ] |
Error: the argument should be a list |
Shuffle[ {1,2}, {3} ] |
Error: the number of arguments should be 1 |
See also: RandomSample, RandomSelect, Sort