From 9a2a0aa5e13ca6df44e30e3474049a8f680d7c5c Mon Sep 17 00:00:00 2001 From: foobar Date: Mon, 11 Aug 2003 00:42:29 +0000 Subject: - Fixed bug #25007 (rand() & mt_rand() seed RNG every call). # Also cleaned up the code a bit with this fix. --- ext/standard/rand.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'ext/standard/rand.c') diff --git a/ext/standard/rand.c b/ext/standard/rand.c index c457fc490d..78737f4caa 100644 --- a/ext/standard/rand.c +++ b/ext/standard/rand.c @@ -53,6 +53,9 @@ PHPAPI void php_srand(long seed TSRMLS_DC) srand((unsigned int) seed); # endif #endif + + /* Seed only once */ + BG(rand_is_seeded) = 1; } /* }}} */ @@ -198,6 +201,9 @@ PHPAPI void php_mt_srand(php_uint32 seed TSRMLS_DC) for (BG(left) = 0, *s++ = x, j = N; --j; *s++ = (x *= 69069U) & 0xFFFFFFFFU); + + /* Seed only once */ + BG(mt_rand_is_seeded) = 1; } /* }}} */ @@ -246,12 +252,6 @@ PHPAPI php_uint32 php_mt_rand(TSRMLS_D) } /* }}} */ -#ifdef PHP_WIN32 -#define GENERATE_SEED() ((long) (time(0) * GetCurrentProcessId() * 1000000 * php_combined_lcg(TSRMLS_C))) -#else -#define GENERATE_SEED() ((long) (time(0) * getpid() * 1000000 * php_combined_lcg(TSRMLS_C))) -#endif - /* {{{ proto void srand([int seed]) Seeds random number generator */ PHP_FUNCTION(srand) @@ -265,7 +265,6 @@ PHP_FUNCTION(srand) seed = GENERATE_SEED(); php_srand(seed TSRMLS_CC); - BG(rand_is_seeded) = 1; } /* }}} */ @@ -282,7 +281,6 @@ PHP_FUNCTION(mt_srand) seed = GENERATE_SEED(); php_mt_srand(seed TSRMLS_CC); - BG(mt_rand_is_seeded) = 1; } /* }}} */ -- cgit v1.2.1