Just a different spin on this one would be to create an array containing
sequential numbers, then shuffling them. This meets your criteria that they
be unique. However it adds an unspecified condition that all numbers in a
range are represented.
A good shuffle algorithm (fisher-yates shuffle) for perl located in the perl
cookbook: 4.17 pg 121.
-----Original Message-----
From: Scott Taylor [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, June 19, 2001 10:51 AM
To: [EMAIL PROTECTED]
Subject: populating an array with unique integers.
I want to create an array, and populate it with random numbers, they should
be unique and sorted (I can sort at the output). I'm stuck at the unique
part:
generate a random number;
check if the number exists in the array,
if it exists generate a new one,
check again until a unique number is found.
once unique add too next place in array.
I think the perldocs are confusing me.
Thanks.
Scott.