in reply to shuffle array (in place)
for more read perldoc -q shuffle.sub fisher_yates_shuffle { my $deck = shift; # $deck is a reference to an array my $i = @$deck; while ( $i-- ) { my $j = int rand( $i + 1 ); @$deck[ $i, $j ] = @$deck[ $j, $i ]; } } my @aa = qw/a b c d e f/; fisher_yates_shuffle( \@aa );
|
|---|