Re: Ahh! Array!!
| From: | Joseph Koenig | Date: | Wed, 02 Aug 2000 20:13:44 +0000 |
| Subject: | Re: Ahh! Array!! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-9809@lists.php.net to get a copy of this message | ||
It worked!! Looks like my biggest problem was not seeding the random number
generator...even though the manual has a note about it. For some reason I
thought I didn't need to. Sounds like someone needs a nap....Thanks a lot.
Joe
Vamsi Nath wrote:
> Hi Joe,
> Try this code..it worked for me:
>
> <?php
> srand((double)microtime()*1000000);
> $id = array();
>
> while(count($id) < 6) {
> $pick = rand(1,10);
> $is_valid = TRUE;
> for ($j=0; $j<count($id); ++$j) {
> if ($pick == $id[$j]) {
> $is_valid = FALSE;
> break;
> }
> }
> if($is_valid) {
> $id[] = $pick;
> }
> }
> print "Random numbers: ";
>
> while(list(,$val) = each($id)) {
> print "$val ";
> }
> ?>
>
> Hope this helps!
>
> --Vamsi
> http://php.vamsi.net