note 88728 added to function.rand

From: Date: Wed, 04 Feb 2009 22:28:50 +0000
Subject: note 88728 added to function.rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-150234@lists.php.net to get a copy of this message
My questions is this: We have a code that uses the rand() function to execute a percentage of the time. here's the code: <? $random = rand(0, 100); echo $random; echo "\n"; ?> and I have a shell script to test the number of times the random number will be less then the frequency of 80 as follows. count=1 frequency=80 while [ $count -lt 1000 ] do randomnumber=php AdSource.php | tail -n 1 count=expr $count + 1 if test $randomnumber -lt $frequency then echo "random number is less then $frequency" fi done ~ ~ ~ ~ And the random number generated in php is less then the $frequency by a difference of 10 at most. This works for what I need to do, but why? How does the rand() function work? ---- Server IP: 209.41.74.194 Probable Submitter: 69.198.90.186 ---- Manual Page -- http://www.php.net/manual/en/function.rand.php Edit -- https://master.php.net/note/edit/88728 Del: integrated -- https://master.php.net/note/delete/88728/integrated Del: useless -- https://master.php.net/note/delete/88728/useless Del: bad code -- https://master.php.net/note/delete/88728/bad+code Del: spam -- https://master.php.net/note/delete/88728/spam Del: non-english -- https://master.php.net/note/delete/88728/non-english Del: in docs -- https://master.php.net/note/delete/88728/in+docs Del: other reasons-- https://master.php.net/note/delete/88728 Reject -- https://master.php.net/note/reject/88728 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#150234) next »