Knuth shuffle: Difference between revisions

(→‎{{header|Rust}}: Updated to the Rust 1.2.0)
Line 2,023:
The shuffle is also built into the pick method on lists when you pass it a "whatever" for the number to pick:
<lang perl6>my @deck = @cards.pick(*);</lang>
 
=={{header|Phix}}==
<lang Phix>sequence cards = tagset(52)
puts(1,"Before: ") ?cards
for i=52 to 1 by -1 do
integer r = rand(i)
{cards[r],cards[i]} = {cards[i],cards[r]}
end for
puts(1,"After: ") ?cards
puts(1,"Sorted: ") ?sort(cards)</lang>
{{out}}
<pre>
Before: {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52}
After: {42,4,48,28,11,3,52,51,22,2,49,38,25,33,27,35,18,44,5,7,21,13,36,29,43,6,9,31,10,30,20,16,46,34,8,17,14,45,37,24,32,41,50,15,39,40,47,23,1,12,26,19}
Sorted: {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52}
</pre>
 
=={{header|PHP}}==
7,820

edits