summaryrefslogtreecommitdiff
path: root/ext/standard/rand.c
diff options
context:
space:
mode:
authorfoobar <sniper@php.net>2003-08-11 00:42:29 +0000
committerfoobar <sniper@php.net>2003-08-11 00:42:29 +0000
commit9a2a0aa5e13ca6df44e30e3474049a8f680d7c5c (patch)
tree4fb319e21c5a1a2b804681cea093e6e6db7c1eb3 /ext/standard/rand.c
parentad29f2f0064c56d1f464410511adbcab1a42938a (diff)
downloadphp-git-9a2a0aa5e13ca6df44e30e3474049a8f680d7c5c.tar.gz
- Fixed bug #25007 (rand() & mt_rand() seed RNG every call).
# Also cleaned up the code a bit with this fix.
Diffstat (limited to 'ext/standard/rand.c')
-rw-r--r--ext/standard/rand.c14
1 files changed, 6 insertions, 8 deletions
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;
}
/* }}} */