Getrandmax () why is the limit 32767 on windows?

PHP returns maximum possible random value 32767 on windows?

What is the window limit?

echo getrandmax(); //32767 
+6
source share
1 answer

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:

 /* System Rand functions */ #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.

+9
source

Source: https://habr.com/ru/post/908255/


All Articles