Feed on
Posts
Comments

here’s one legitimate way to randomize an array in perl:

# fisher_yates_shuffle( \@array )
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];
}
}

thanks perl cookbook!


Bookmark and Share

if that was helpful ...

check out the other tips and tricks i've compiled on these pages. you might learn something else interesting!

Did I get this wrong? Let me know!

Trackback URI | Comments RSS