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 '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
>   $random{random_number()} = 1 until keys %random == $limit;


>That loop, if it's too concise for you, is:

A bit, yup.

>   until (keys(%random) == $limit) {
>     my $r = random_number();
>     $random{$r} = 1;
>   }

That makes sense to me, and it works great, thanks.

Now I need to clear that hash so I can do it again; I'm trying to build a 
table of sets of numbers.

This is what I have so far, but it's wrong.

until (keys(%MyTable) == $num_sets) {
     until (keys(%Random) == $per_set) {
         my $r = $thenum = int(rand() * $newmax ) + $min;
         $Random{$r} = 1;
         }

     foreach my $MyKey (sort keys %Random) {
         $theset = $theset ." ". $MyKey;
         }

     $MyTable{$theset} = 1;
#    $theset = "";
#    delete @Random;  How do I clear the entire @Random table, so I can 
start again?
     }

Reply via email to