sub fisher_yates_shuffle($) { my $array = shift; my $i, $j; for ($i = @$array; --$i; ) { $j = int rand($i+1); next if $i == $j; @$array[$i,$j] = @$array[$j,$i]; } } sub example_use() { my(@a) = qw(aaa bbb ccc ddd); fisher_yates_shuffle(\@a); }Source: perl cookbook
Programming Tips - perl: How can I shuffle (randomize) an array
Date: 2009dec27
Language: perl
Q. perl: How can I shuffle (randomize) an array
A. Here's a function that does it: