From e541a27eed8d024678e08d69d71c2c76a5e253e2 Mon Sep 17 00:00:00 2001 From: Jim Jagielski Date: Tue, 6 Feb 2001 16:27:08 +0000 Subject: [PATCH] For those lucky systems with both random() and *rand48(), the random() family is the prefered choice. So if both exist, we now choose that. --- ChangeLog | 7 +++++++ NEWS | 1 + ext/standard/array.c | 12 ++++++------ ext/standard/crypt.c | 12 ++++++------ ext/standard/rand.c | 12 ++++++------ 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index a3efea6f8c..b4e2876157 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2001-02-06 Jim Jagielski + + * ext/standard/array.c: + ext/standard/crypt.c: + ext/standard/rand.c: + Prefer the random() family over the *rand48() one + 2001-02-05 Zeev Suraski * ext/com/typedef_VARIANT.c diff --git a/NEWS b/NEWS index 471e4aa693..cbd382a1e3 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ PHP 4.0 NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 200?, Version 4.0.5 +- Prefer random() over *rand48() (JimJag) - Sped up WDDX serialization 2x. (Andrei) - Added a new parameter to mail() which appends aditional command line parameters to the mail program. (Derick) diff --git a/ext/standard/array.c b/ext/standard/array.c index 0060a1355a..6d44cc4c25 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -1328,11 +1328,11 @@ PHP_FUNCTION(range) static int array_data_shuffle(const void *a, const void*b) { return ( /* This is just a little messy. */ -#ifdef HAVE_LRAND48 - lrand48() -#else #ifdef HAVE_RANDOM random() +#else +#ifdef HAVE_LRAND48 + lrand48() #else rand() #endif @@ -2703,11 +2703,11 @@ PHP_FUNCTION(array_rand) zend_hash_internal_pointer_reset(Z_ARRVAL_PP(input)); while (num_req_val && (key_type = zend_hash_get_current_key(Z_ARRVAL_PP(input), &string_key, &num_key, 0)) != HASH_KEY_NON_EXISTANT) { -#ifdef HAVE_LRAND48 - randval = lrand48(); -#else #ifdef HAVE_RANDOM randval = random(); +#else +#ifdef HAVE_LRAND48 + randval = lrand48(); #else randval = rand(); #endif diff --git a/ext/standard/crypt.c b/ext/standard/crypt.c index d4cc55b43c..2293b7aed8 100644 --- a/ext/standard/crypt.c +++ b/ext/standard/crypt.c @@ -85,10 +85,10 @@ extern char *crypt(char *__key,char *__salt); #define PHP_STD_DES_CRYPT 1 #endif -#if HAVE_LRAND48 -#define PHP_CRYPT_RAND lrand48() -#elif HAVE_RANDOM +#if HAVE_RANDOM #define PHP_CRYPT_RAND random() +#elif HAVE_LRAND48 +#define PHP_CRYPT_RAND lrand48() #else #define PHP_CRYPT_RAND rand() #endif @@ -105,10 +105,10 @@ PHP_MINIT_FUNCTION(crypt) REGISTER_LONG_CONSTANT("CRYPT_MD5", PHP_MD5_CRYPT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("CRYPT_BLOWFISH", PHP_BLOWFISH_CRYPT, CONST_CS | CONST_PERSISTENT); -#if HAVE_SRAND48 - srand48((long) time(0) * (long) getpid() * (long) (php_combined_lcg() * 10000.0)); -#elif HAVE_SRANDOM +#if HAVE_SRANDOM srandom((unsigned int) time(0) * getpid() * (php_combined_lcg() * 10000.0)); +#elif HAVE_SRAND48 + srand48((long) time(0) * (long) getpid() * (long) (php_combined_lcg() * 10000.0)); #else srand((unsigned int) time(0) * getpid() * (php_combined_lcg() * 10000.0)); #endif diff --git a/ext/standard/rand.c b/ext/standard/rand.c index 0413e31269..b184a75cec 100644 --- a/ext/standard/rand.c +++ b/ext/standard/rand.c @@ -199,11 +199,11 @@ PHP_FUNCTION(srand) WRONG_PARAM_COUNT; } convert_to_long_ex(arg); -#ifdef HAVE_SRAND48 - srand48((unsigned int) (*arg)->value.lval); -#else #ifdef HAVE_SRANDOM srandom((unsigned int) (*arg)->value.lval); +#else +#ifdef HAVE_SRAND48 + srand48((unsigned int) (*arg)->value.lval); #else srand((unsigned int) (*arg)->value.lval); #endif @@ -253,11 +253,11 @@ PHP_FUNCTION(rand) } return_value->type = IS_LONG; -#ifdef HAVE_LRAND48 - return_value->value.lval = lrand48(); -#else #ifdef HAVE_RANDOM return_value->value.lval = random(); +#else +#ifdef HAVE_LRAND48 + return_value->value.lval = lrand48(); #else return_value->value.lval = rand(); #endif -- 2.50.1