Stass [S], on Friday, January 27, 2006 at 12:21 (+0600) wrote the
following:
S> Can someone suggest an optimized algorythm of the random playlist?
S> I can make it through array - but it is not good in my mind to rearrange
S> the array after element delete...
if you know shuffle good algorythm such as:
# fisher_yates_shuffle( [EMAIL PROTECTED] ) : generate a random permutation
# of @array in place
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];
}
}
fisher_yates_shuffle( [EMAIL PROTECTED] ); # permutes @array in place
(^^from Oreilly Perl Bookshelf)
you can always remove undef elements from array. Also I suggest you
read:
perldoc -f splice
--
How do you protect mail on web? I use http://www.2pu.net
["Freedom cannot be legislated" - M. Muir, Suicidal Tendencies]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>