Re: Random number generator

From: Date: Thu, 06 Nov 2008 17:28:38 +0000
Subject: Re: Random number generator
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-283011@lists.php.net to get a copy of this message
WEISD wrote: > >> >> Computer functions to generate random numbers are not designed to do >> what their name suggests. >> >> Software testing requires repeatability, and this includes random >> number generation. >> >> Without knowing how PHP seeds the generator it is difficult to predict >> what it will do. >> >> I still think taking the last digit of the current time is your best >> solution. >> >> Stephen > > I like the idea of using the time but don't like the idea of spending > the rest of the day learning how to parse out the numbers I need from > the time... > Really, you think this step is difficult? Try looking at the page http://php.net/date it will give you all that you need. $second = (int)date('s'); This will give you the current second of the current minute of the current .... Anyways. Take that and run it through a modulo then add one to keep it within the 1-10. <?php $second = (((int)date('s')) % 10) +1; echo $second; ?> This should do -- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare

« previous php.general (#283011) next »