Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
What is wrong with this?my $username = shuffle(\@usernames); print $username; # prints 0!! sub 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]; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: randomize array
by runrig (Abbot) on Mar 29, 2006 at 01:17 UTC | |
|
Re: randomize array
by rafl (Friar) on Mar 29, 2006 at 01:05 UTC | |
|
Re: randomize array
by bart (Canon) on Mar 29, 2006 at 06:54 UTC | |
|
Re: randomize array
by Cody Pendant (Prior) on Mar 29, 2006 at 08:16 UTC | |
|
Re: randomize array
by NetWallah (Canon) on Mar 29, 2006 at 05:09 UTC | |
by Thelonius (Priest) on Mar 29, 2006 at 06:31 UTC |