diff options
Diffstat (limited to 'ext/standard/mt_rand.c')
-rw-r--r-- | ext/standard/mt_rand.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/ext/standard/mt_rand.c b/ext/standard/mt_rand.c index 3c33a42df3..d49740d40e 100644 --- a/ext/standard/mt_rand.c +++ b/ext/standard/mt_rand.c @@ -24,6 +24,7 @@ #include "php.h" #include "php_rand.h" +#include "php_random.h" #include "php_mt_rand.h" /* MT RAND FUNCTIONS */ @@ -161,7 +162,11 @@ PHPAPI uint32_t php_mt_rand(void) register uint32_t s1; if (UNEXPECTED(!BG(mt_rand_is_seeded))) { - php_mt_srand(GENERATE_SEED()); + zend_long bytes; + if (php_random_bytes_silent(&bytes, sizeof(zend_long)) == FAILURE) { + bytes = GENERATE_SEED(); + } + php_mt_srand(bytes); } if (BG(left) == 0) { @@ -189,8 +194,11 @@ PHP_FUNCTION(mt_srand) Z_PARAM_LONG(mode) ZEND_PARSE_PARAMETERS_END(); - if (ZEND_NUM_ARGS() == 0) - seed = GENERATE_SEED(); + if (ZEND_NUM_ARGS() == 0) { + if (php_random_bytes_silent(&seed, sizeof(zend_long)) == FAILURE) { + seed = GENERATE_SEED(); + } + } switch (mode) { case MT_RAND_PHP: |