in reply to random number
Here's a snippit that will initialize an array and select a number while the array still has elements...what you do with the element is up to you...
Addendum: See BrowserUk's reply for a more tidy/efficient method of extracting the element from the arrayuse strict; my $max = 200; #number of elements for +array my @array = (0..$max-1); #initialize array while(@array !=0){ my $index = rand @array; #pick a random element o +f the existing array my $element = $array[$index]; #extract the element my @newarray = grep {$_ !=$element} @array; #remove the element @array = @newarray; #reset the array }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: random number
by BrowserUk (Pope) on Dec 13, 2002 at 04:22 UTC | |
by I0 (Priest) on Dec 14, 2002 at 23:35 UTC | |
by BrowserUk (Pope) on Dec 15, 2002 at 00:19 UTC | |
Re: Re: random number
by sauoq (Abbot) on Dec 13, 2002 at 23:40 UTC | |
Re: Re: random number
by huskey (Beadle) on Dec 14, 2002 at 04:53 UTC |
In Section
Seekers of Perl Wisdom