RosettaCodeData/Task/Knuth-shuffle/Mathematica/knuth-shuffle-2.math
2023-07-01 13:44:08 -04:00

10 lines
258 B
Text

Shuffle[input_List /; Length[input] >= 1] :=
Module[{indices = {}, allindices = Range[Length[input]]},
Do[
AppendTo[indices,
Complement[allindices, indices][[RandomInteger[{1, i}]]]];
,
{i, Length[input], 1, -1}
];
input[[indices]]
]