in reply to Re: Re: Choose random element of array?
in thread Choose random element of array?

Nice snippet. I couldn't help but point out that you already have a built-in counter -- the number of elements in the array. Reworking your example a bit, we get the following:
use strict; my $randstring; my @testarray = ( 'a' .. 'z', 'A' .. 'Z', '0' .. '999' ); $randstring .= splice(@testarray, rand @testarray, 1) while @testarray; print "$randstring\n";
Cheers,
Matt

Replies are listed 'Best First'.
Re: Re^3: Choose random element of array?
by hsinclai (Deacon) on May 29, 2004 at 03:23 UTC

    That's definitely better -thanks!