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

chakreey has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I am trying to generate set of unique random numbers. Here is my script for doing this

use strict; use warnings; my (@RandomSet,$random_number, $element_of_array, $count); foreach(1..10){ $random_number = int(rand(1185)); $count=0; foreach $element_of_array (@RandomSet){ if ($random_number == $element_of_array){ $count++; } } push (@RandomSet,$random_number) if $count==0; } foreach $element_of_array (@RandomSet){ print "$element_of_array\n"; }

for every new random number generated, I am finding out if it is unique or a repeat. Is there a better/faster way to achieve this ?

TIA