Re: Random numbers
| From: | Folke Ashberg | Date: | Sat, 25 Nov 2000 00:55:44 +0000 |
| Subject: | Re: Random numbers | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-27065@lists.php.net to get a copy of this message | ||
<?
while ($ok<6){
$rand=rand(1,9);
print "$rand<BR>\n";
if ($numbers[$rand]<2){
$numbers[$rand]++;
$ok++;
}
}
?>
--
Folke Ashberg
Stage Internet Services GmbH
Technical Development
folke@fanstage.de
folke@fanstage.de | Tel: +49 89 454591-77 | Fax: +49 89 454591-71
Kreillerstr. 21 | 81673 Munich | Germany | www.fanstage.de
On Fri, 24 Nov 2000, CDitty wrote:
> Hello all,
>
> I need to generate 6 random numbers, 1-9, and make sure that there are no
> more than 2 matches for each number.
> ie...
> 1, 2, 3, 1,2,4 - good
> 1, 3, 5, 8, 4, 3, 3 - not good
>
> Does anyone have or can anyone help me with this code?
>
> Thanks
>
> Chris
>
>
>