RosettaCodeData/Task/Knuth-shuffle/Mathematica/knuth-shuffle-2.math
Ingy döt Net d066446780 langs a-z
2013-04-10 22:43:41 -07: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]]
]