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 is defined as:
#ifndef RAND_MAX #define RAND_MAX (1<<15) #endif
So, if RAND_MAX exists, it is used ...
... And on Windows with Visual Studio there really exists a RAND_MAX defined (citation):
The RAND_MAX is the maximum value that rand can return. RAND_MAX defined as the value 0x7fff .
So basically, getrandmax() returns 32767 , because the way it is defined on Windows and PHP often uses what the underlying system exports.
source share