in reply to random index in array - no duplicates
This is the Fisher-Yates algorithm, shuffles the array in place - very efficient, and lifted straight from perldoc -q shufflemy $array = shift; my $i; for ($i = @$array; --$i; ) { my $j = int rand ($i+1); @$array[$i,$j] = @$array[$j,$i]; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: random index in array - no duplicates
by samtregar (Abbot) on Jun 07, 2002 at 01:03 UTC | |
|
Re: Re: random index in array - no duplicates
by jryan (Vicar) on Jun 08, 2002 at 00:35 UTC | |
by jsprat (Curate) on Jun 08, 2002 at 06:44 UTC |