Re: populating an array with unique integers.

2001-06-19 Thread Jeff 'japhy' Pinyan
On Jun 19, Jeff 'japhy' Pinyan said: > until (keys(%table) == $num_sets) { >my %random; > ># until we have the proper number of random numbers >until (keys(%random) == $per_set) { > # put a random number in the hash > $random{ $min + int rand $newmax } = 1; >} > >$t

RE: populating an array with unique integers.

2001-06-19 Thread Wagner-David
undef %Random; or %Random = (); Wags ;) -Original Message- From: Scott Taylor [mailto:[EMAIL PROTECTED]] Sent: Tuesday, June 19, 2001 11:52 To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: populating an array with unique integers. At 10:30 AM 06/19/01, Jeff '

Re: populating an array with unique integers.

2001-06-19 Thread Scott Taylor
At 10:30 AM 06/19/01, Jeff 'japhy' Pinyan wrote: >On Jun 19, Scott Taylor said: > > >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: > > $limit = 10; # we want 10 random numbers >

RE: populating an array with unique integers.

2001-06-19 Thread blowther
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)

Re: populating an array with unique integers.

2001-06-19 Thread Jeff 'japhy' Pinyan
On Jun 19, Scott Taylor said: >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: Whenever you hear "unique", you should think "I should be using a hash." The same goes for "in" and "dupli

RE: populating an array with unique integers.

2001-06-19 Thread Wagner-David
Sorry but foreach should be: foreach my $MyKey (sort keys %Unique ) { Wags ;) -Original Message- From: Wagner-David Sent: Tuesday, June 19, 2001 09:57 To: [EMAIL PROTECTED] Subject: RE: populating an array with unique integers. Use a hash vs array, use the

RE: populating an array with unique integers.

2001-06-19 Thread Wagner-David
Use a hash vs array, use the number as a hash key. If key exists, then get the next number until you have the number of unique numbers desired. next if ( exists $Unique{$RandomNumber} ); $Unique{$RandomNumber} = 1; for printing: foreach my $MyKey (sort k