http://qs1969.pair.com?node_id=139915


in reply to Random but non-repeating array loop

As japhy suggests, the Fisher-Yates shuffle is a good solution. If you want to save yourself the trouble of coding it, I've got it implemented in Math::NumberCruncher. Math::NumberCruncher also has numerous other similar functions that may be useful. Using Math::NumberCruncher, you could do the above like so:
use strict; use Math::NumberCruncher; my @chars = ( 'A' .. 'Z' ); my $ref = Math::NumberCruncher->new(); $ref->ShuffleArray( \@chars ); foreach my $char ( @chars ) { print $char, "\n"; }

UPDATE: Pursuant to Juerd's post, in the interest of TMTOWTDI, here's the code using Math::NumberCruncher through its original functional interface:
use strict; use Math::NumberCruncher; my @chars = ( 'A' .. 'Z' ); Math::NumberCruncher::ShuffleArray( \@chars ); foreach my $char ( @chars ) { print $char, "\n"; }


___________________
Kurt