Note, the function used by PHP to constrain a random number
between (min, max) is the following:
$number = $min + (($max - $min + 1) * ($number / ($rand_max
+ 1));
where the following:
$number - the initially generated random number
$min - the minimum in the range
$max - the maximum in the range
$rand_max - the maximum possible random value
What this algorithm does is constrain the generated number
to a 0-1 range, then multiply it against your range, mapping
the two to each other.
In practice you'll see the following results:
For a generated $number of 16384 and a $rand_max of 32768:
rand(0, 10) = 5
rand(0, 100) = 50
rand(0, 1000) = 500
with the additional property that if the range you're asking
for is larger than $rand_max, random numbers will be in a
multiple of $max/$rand_max.
----
Server IP: 87.124.64.96
Probable Submitter: 62.3.216.18
----
Manual Page -- http:/
/www.php.net/manual/en/function.rand.php
Edit -- https://master
.php.net/note/edit/78986
Del: integrated -- h
ttps://master.php.net/note/delete/78986/integrated
Del: useless -- http
s://master.php.net/note/delete/78986/useless
Del: bad code -- htt
ps://master.php.net/note/delete/78986/bad+code
Del: spam -- https:/
/master.php.net/note/delete/78986/spam
Del: non-english --
https://master.php.net/note/delete/78986/non-english
Del: in docs -- http
s://master.php.net/note/delete/78986/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/78986
Reject -- https://mast
er.php.net/note/reject/78986
Search -- https://
master.php.net/manage/user-notes.php
--
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php
|