in reply to Array Shuffler

Cool...

'perldoc -f shuffle' does it like this:
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]; } }

GreetZ!,

print "profeth still\n" if /bird|devil/;

Replies are listed 'Best First'.
Re: Re: Array Shuffler
by runrig (Abbot) on Jan 09, 2001 at 21:28 UTC
    And for an array of any significant size (~20 elements or more) that 'next if..' line just slows down the algorithm.
      Yup. This was discussed at length here.