sourcecode
zencrypt
<code>
sub shuffle {
srand(time ^ ($$ + ($$ << 15))); # For pre-Perl 5.004.
$r_deck = shift;
$deck_l = scalar(@$r_deck);
for ($i=0; $i<$deck_l; $i++) {
$rand = int(rand($deck_l)); # Find random integer betwen
# 0 and one less than the length
# of the array (deck).
($r_deck->[$i], $r_deck->[$rand]) = ($r_deck->[$rand], $r_deck->[$i]);
# You gotta love Perl, don't you? #
# Switch their values. #
}
}
</code>
I think too much emphasis is placed on sorting lists. Bubblesort this, and quicksort that, and selection sort something else. But what about random shuffling? I never see any attention given to the opposite of sorting; shuffling! I wrote out some basic code that i think does the trick, but if anyone has any tips on how it can be improved, please let me know. thanks
Fun Stuff
agentzen@nmt.edu