Re: Random number generator

From: Date: Thu, 06 Nov 2008 16:09:09 +0000
Subject: Re: Random number generator
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-283001@lists.php.net to get a copy of this message
On Thu, Nov 6, 2008 at 10:53 AM, WEISD <pzig@weisd.com> wrote: > > ""Gary M. Josack"" <lists@byoteki.com> wrote in message > news:4911EC29.8070309@byoteki.com... >> >> Stephen wrote: >>>> >>>> On a php web page I want to generate a random number between say 1 and >>>> 10 and then use that number to reference a particular file in >>>> an include tag. >>>> >>>> <?php include('GeneratedNumber.html'); ?> >>>> >>>> Is there an easy way to do this? >>>> >>> >>> Get the time and use the last digit converting 0 to 10. >>> >>> Stephen >>> >>> >> rand(1, 10); > > Thanks for the help!! > > php's random number generator seems to have favorite numbers. > > rand(1, 10); produces 10 & 3, 90% of the time.... > That is strange. I get pretty balanced results on this computer. <?php $histogram = array_fill(1, 10, 0); $iterations = 200000; for ($i = 0; $i < $iterations; ++$i) { ++$histogram[round(rand(1, 10))]; } print_r($histogram); ?> Array ( [1] => 19991 (10.00%) [2] => 19981 (9.99%) [3] => 20011 (10.01%) [4] => 19998 (10.00%) [5] => 20049 (10.02%) [6] => 20008 (10.00%) [7] => 19983 (9.99%) [8] => 19986 (9.99%) [9] => 20007 (10.00%) [10] => 19986 (9.99%) ) Andrew

« previous php.general (#283001) next »