Knuth shuffle: Difference between revisions
m
→{{header|Joy}}
m (→{{header|BASIC}}: alphabetized subheaders) |
m (→{{header|Joy}}) |
||
Line 2,754:
=={{header|Joy}}==
<
(* 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.</
Using knuth-shuffle (file shuffle.joy):
<
[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20]
knuth-shuffle.</
Command line:
: <tt>joy shuffle.joy</tt>
|