mumble jumbling.
Leon Brocard
acme at astray.com
Thu Jan 3 03:58:55 CST 2002
Stray Toaster sent the following bits through the ether:
> I want to take an array, and then make another out of it, albeit a
> jumbled up version. Now there is bound to be a nice way of doing this.
'perldoc -q shuffle' introduces you to the nice Fisher Yates Shuffle,
which in your code would be equal to:
my $fisher_yates_shuffle = sub {
my $array = [@_];
my $i;
for ($i = @$array; --$i; ) {
my $j = int rand ($i+1);
@$array[$i,$j] = @$array[$j,$i];
}
return @$array;
};
HTH, Leon
--
Leon Brocard.............................http://www.astray.com/
Nanoware...............................http://www.nanoware.org/
... Windows Error: 002 No error, yet
More information about the Belfast-pm
mailing list