my @array = qw /one two three four five six/; for (my $i = @array; -- $i;) { my $r = int rand (1 + $i); @array [$i, $r] = @array [$r, $i] unless $r == $i; }
Or use Algorithm::Numerical::Shuffle which implements this for you
use Algorithm::Numerical::Shuffle qw/shuffle/; my @array = shuffle qw/one two three four five/;
Cheers,
KM
In reply to RE: Randomize an array
by KM
in thread Randomize an array
by Zebu
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |