From e36faa1eaeecc8db20ed9b6d9820ca25ffc69d0b Mon Sep 17 00:00:00 2001 From: Andrea Faulds Date: Sun, 11 Jan 2015 01:55:26 +0000 Subject: [PATCH] Clarity on behaviour of mt_getrandmax() and mt_rand()'s max git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@335710 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/math/functions/mt-getrandmax.xml | 5 ++++- reference/math/functions/mt-rand.xml | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/reference/math/functions/mt-getrandmax.xml b/reference/math/functions/mt-getrandmax.xml index 1f82f810bc..2ae1b3c67a 100644 --- a/reference/math/functions/mt-getrandmax.xml +++ b/reference/math/functions/mt-getrandmax.xml @@ -19,7 +19,10 @@ &reftitle.returnvalues; - Returns the maximum random value returned by mt_rand + Returns the maximum random value returned by a call to + mt_rand without arguments, which is the maximum value + that can be used for its max parameter without the + result being scaled up (and therefore less random). diff --git a/reference/math/functions/mt-rand.xml b/reference/math/functions/mt-rand.xml index 8e32a52c52..5643deb68d 100644 --- a/reference/math/functions/mt-rand.xml +++ b/reference/math/functions/mt-rand.xml @@ -124,6 +124,9 @@ echo mt_rand(5, 15); The distribution of mt_rand return values is biased towards even numbers on 64-bit builds of PHP when max is beyond 2^32. + This is because if max is greater than + the value returned by mt_getrandmax, the output of the + random number generator must be scaled up.