12 lines
370 B
Text
12 lines
370 B
Text
DEFINE knuth-shuffle ==
|
|
(* Take the size of the array (without destroying it) *)
|
|
dup dup size
|
|
(* Generate a list of as many random numbers *)
|
|
[rand] [rem] enconcat map
|
|
(* Zip the two lists *)
|
|
swap zip
|
|
(* Sort according to the new index number *)
|
|
[small] [] [uncons unswonsd [first >] split [swons] dip2]
|
|
[enconcat] binrec
|
|
(* Delete the new index number *)
|
|
[second] map.
|