Re: Rand() problem

From: Date: Mon, 12 Jan 2004 04:30:59 +0000
Subject: Re: Rand() problem
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-174277@lists.php.net to get a copy of this message
I am running the latest stable PHP release. I am passed values and my range is far less than the max... On my computer with my Xitami webserver this code returns the number 45 over and over: $num = rand(0,50); echo $num; I don't know what to do. The rand function worked a few times then died on me. I dunno if this is a bug or if I am just bad luck. Never had a problem before. It seems that on a different computer it returns a different number than 45 but always the same number over and over. ----- Original Message ----- From: "Richard Davey" <rich@launchcode.co.uk> To: "nefar" <nefar@nefarnet.org> Cc: <php-general@lists.php.net> Sent: Saturday, January 10, 2004 5:26 AM Subject: Re: [PHP] Rand() problem > Hello nefar, > > Friday, January 9, 2004, 6:05:34 AM, you wrote: > > n> After moving my PHP files to a new hard drive and a new windows > n> installation, my rand function gets stuck and only gives you one number over > n> and over. It worked a few times then got stuck. I tried using IIS 5.1 (I > n> was using Xitami) and it gave me the same results. It even gets stuck on > n> the same number as the other webserver. I tried installing on a different > n> machine. Same result. Can anyone help? > > Which version of PHP are you using? If it's earlier than 4.2.0 you > need to see the rand() function first, or it will return the same > numbers each time. Use srand() to do this. > > Also, are you passing in values to the rand() function? (your min and > max values) - on Windows there is a limit on the max value of 32,768. > > -- > Best regards, > Richard > mailto:rich@launchcode.co.uk > > >

« previous php.general (#174277) next »