Re: Rand() problem

From: Date: Mon, 12 Jan 2004 04:47:36 +0000
Subject: Re: Rand() problem
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-174280@lists.php.net to get a copy of this message
On Monday 12 January 2004 12:30, Jon wrote: > I am running the latest stable PHP release. Which is? "Latest" changes over time. Always state the exact version. > 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. If you are using a relatively new version of PHP then there is no need to seed the random number generator. And it is better to use mt_rand() rather than rand() because: - it is supposed to produce better random numbers - is faster than rand() -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * ------------------------------------------ Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general ------------------------------------------ /* No evil can happen to a good man. -- Plato */

« previous php.general (#174280) next »