http://www.perlmonks.org?node_id=219493


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...
use 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 }
Addendum: See BrowserUk's reply for a more tidy/efficient method of extracting the element from the array