Knuth shuffle: Difference between revisions

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

edits