PHP returns largest possible random value 32767 on windows?
What is constraint on windows?
echo getrandmax(); //32767
According to the PHP source-code, getrandmax()
is defined as :
PHP_FUNCTION(getrandmax)
{
if (zend_parse_parameters_none() == FAILURE) {
return;
}
RETURN_LONG(PHP_RAND_MAX);
}
And PHP_RAND_MAX
is defined as :
#define PHP_RAND_MAX RAND_MAX
RAND_MAX
itself being defined as :
/* System Rand functions */
#ifndef RAND_MAX
#define RAND_MAX (1<<15)
#endif
So, if there is an RAND_MAX
defined, it is used...
... And, on Windows with Visual Studio, there is indeed a RAND_MAX
defined (quoting) :
The constant
RAND_MAX
is the maximum value that can be returned by therand
function.RAND_MAX
is defined as the value0x7fff
.
So, basically, getrandmax()
returns 32767
because that's how it's defined on Windows -- and PHP often uses what the underlying system exports.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With