jmoore Wed Feb 21 16:24:19 2001 EDT
Modified files:
/php4/ext/standard array.c crypt.c php_rand.h rand.c
Log:
Adding php_rand() and php_srand(seed) as a wrapper around random, lrand48 and rand.
Index: php4/ext/standard/array.c
diff -u php4/ext/standard/array.c:1.95 php4/ext/standard/array.c:1.96
--- php4/ext/standard/array.c:1.95 Wed Feb 21 09:22:26 2001
+++ php4/ext/standard/array.c Wed Feb 21 16:24:19 2001
@@ -21,7 +21,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: array.c,v 1.95 2001/02/21 17:22:26 andrei Exp $ */
+/* $Id: array.c,v 1.96 2001/02/22 00:24:19 jmoore Exp $ */
#include "php.h"
#include "php_ini.h"
@@ -1364,18 +1364,7 @@
static int array_data_shuffle(const void *a, const void*b) {
- return (
- /* This is just a little messy. */
-#ifdef HAVE_RANDOM
- random()
-#else
-#ifdef HAVE_LRAND48
- lrand48()
-#else
- rand()
-#endif
-#endif
- % 2) ? 1 : -1;
+ return (php_rand() % 2) ? 1 : -1;
}
Index: php4/ext/standard/crypt.c
diff -u php4/ext/standard/crypt.c:1.35 php4/ext/standard/crypt.c:1.36
--- php4/ext/standard/crypt.c:1.35 Tue Feb 6 08:27:08 2001
+++ php4/ext/standard/crypt.c Wed Feb 21 16:24:19 2001
@@ -17,7 +17,7 @@
| Rasmus Lerdorf <[EMAIL PROTECTED]> |
+----------------------------------------------------------------------+
*/
-/* $Id: crypt.c,v 1.35 2001/02/06 16:27:08 jimjag Exp $ */
+/* $Id: crypt.c,v 1.36 2001/02/22 00:24:19 jmoore Exp $ */
#include <stdlib.h>
#include "php.h"
@@ -85,14 +85,10 @@
#define PHP_STD_DES_CRYPT 1
#endif
-#if HAVE_RANDOM
-#define PHP_CRYPT_RAND random()
-#elif HAVE_LRAND48
-#define PHP_CRYPT_RAND lrand48()
-#else
-#define PHP_CRYPT_RAND rand()
-#endif
+#define PHP_CRYPT_RAND php_rand()
+
+
PHP_MINIT_FUNCTION(crypt)
{
#if PHP_STD_DES_CRYPT
@@ -105,13 +101,7 @@
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_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
+ php_srand(time(0) * getpid() * (php_combined_lcg() * 10000.0));
return SUCCESS;
}
Index: php4/ext/standard/php_rand.h
diff -u php4/ext/standard/php_rand.h:1.6 php4/ext/standard/php_rand.h:1.7
--- php4/ext/standard/php_rand.h:1.6 Sun Jul 2 16:46:47 2000
+++ php4/ext/standard/php_rand.h Wed Feb 21 16:24:19 2001
@@ -19,7 +19,7 @@
| Based on code from: Shawn Cokus <[EMAIL PROTECTED]> |
+----------------------------------------------------------------------+
*/
-/* $Id: php_rand.h,v 1.6 2000/07/02 23:46:47 sas Exp $ */
+/* $Id: php_rand.h,v 1.7 2001/02/22 00:24:19 jmoore Exp $ */
#ifndef PHP_RAND_H
#define PHP_RAND_H
@@ -34,6 +34,28 @@
#define PHP_RAND_MAX 2147483647
#else
#define PHP_RAND_MAX RAND_MAX
+#endif
+
+/* Define rand Function wrapper */
+#ifdef HAVE_RANDOM
+#define php_rand() random()
+#else
+#ifdef HAVE_LRAND48
+#define php_rand() lrand48()
+#else
+#define php_rand() rand()
+#endif
+#endif
+
+/* Define srand Function wrapper */
+#ifdef HAVE_SRANDOM
+#define php_srand(seed) srandom((unsigned int)seed)
+#else
+#ifdef HAVE_SRAND48
+#define php_srand(seed) srand48((long)seed)
+#else
+#define php_srand(seed) srand((unsigned int)seed)
+#endif
#endif
#endif /* PHP_RAND_H */
Index: php4/ext/standard/rand.c
diff -u php4/ext/standard/rand.c:1.23 php4/ext/standard/rand.c:1.24
--- php4/ext/standard/rand.c:1.23 Mon Feb 19 11:20:47 2001
+++ php4/ext/standard/rand.c Wed Feb 21 16:24:19 2001
@@ -19,7 +19,7 @@
| Based on code from: Shawn Cokus <[EMAIL PROTECTED]> |
+----------------------------------------------------------------------+
*/
-/* $Id: rand.c,v 1.23 2001/02/19 19:20:47 derick Exp $ */
+/* $Id: rand.c,v 1.24 2001/02/22 00:24:19 jmoore Exp $ */
#include <stdlib.h>
@@ -199,15 +199,7 @@
WRONG_PARAM_COUNT;
}
convert_to_long_ex(arg);
-#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
-#endif
+ php_srand((*arg)->value.lval);
}
/* }}} */
@@ -253,15 +245,9 @@
}
return_value->type = IS_LONG;
-#ifdef HAVE_RANDOM
- return_value->value.lval = random();
-#else
-#ifdef HAVE_LRAND48
- return_value->value.lval = lrand48();
-#else
- return_value->value.lval = rand();
-#endif
-#endif
+
+ return_value->value.lval = php_rand();
+
/*
* A bit of tricky math here. We want to avoid using a modulus because
* that simply tosses the high-order bits and might skew the distribution
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]