in reply to removing arbitrary elements from an array?
This, walks backwards through the array (thus avoiding the repetition problem), swapping cards randomly. I would call this on your deck and then, depending on your card game, treat @deck as a queue.sub fisher_yates_shuffle { my $array = shift; my $i; for ($i = @$array; --$i; ) { my $j = int rand ($i+1); next if $i == $j; @$array[$i,$j] = @$array[$j,$i]; } } fisher_yates_shuffle( \@array );
|
|---|