Perl rand / srand function
Hello
(New to perl script and programming)
I want to generate 10 random numbers between 1-20, but I only want them listed once in my list.
I have the below script, which works, but I have noticed every now and then, it generates duplicates within the list. I understand it would do this, as its non the wiser (my lack of code), so does anyone know how I would be able to do this in my script or any pointers on how I could only get 10 unique numbers all the time?
I have run both rand and srand - same results
$x=1;
$y=20;
$looptimes=10;
while ($looptimes) {
$mynumbers = int(rand ($y - $x + 1)) + $x, "\n";
print $mynumbers;
$looptimes--;
}
Dee
|