summaryrefslogtreecommitdiff
path: root/ext/standard/php_rand.h
diff options
context:
space:
mode:
authorfoobar <sniper@php.net>2001-09-05 19:47:55 +0000
committerfoobar <sniper@php.net>2001-09-05 19:47:55 +0000
commit42b5521af505eaddfd4891703da8120865896258 (patch)
treec80bb41e38dba221361ce7eb504f28eb557014bd /ext/standard/php_rand.h
parent24b54b866fc36fed094c1f455e0174c99c24ee40 (diff)
downloadphp-git-42b5521af505eaddfd4891703da8120865896258.tar.gz
revert bad commit.
Diffstat (limited to 'ext/standard/php_rand.h')
-rw-r--r--ext/standard/php_rand.h117
1 files changed, 31 insertions, 86 deletions
diff --git a/ext/standard/php_rand.h b/ext/standard/php_rand.h
index d90b5583aa..b4d7e991d0 100644
--- a/ext/standard/php_rand.h
+++ b/ext/standard/php_rand.h
@@ -15,102 +15,47 @@
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
| Zeev Suraski <zeev@zend.com> |
| Pedro Melo <melo@ip.pt> |
- | Jeroen van Wolffelaar <jeroen@php.net> |
| |
| Based on code from: Shawn Cokus <Cokus@math.washington.edu> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
-/* Layout implementation random functions
- *
- * The PHPAPI contains these functions:
- * - long php_rand()
- * - long php_rand_range(long min, long max)
- * - void php_srand()
- * - long php_getrandmax()
- *
- * Note that it is not possible to choose the algoritm. This is done to
- * give the user the possibility to control all randomness by means of
- * srand()/php.ini in a portable and consistent way.
- *
- *
- * --Jeroen
- */
-
-/* TODO:
- * - make constants available to PHP-user
- * - MINFO section about which random number generators are available
- * - Nuke randmax by enhancing PHP_RAND_RANGE to work well in the case of a
- * greater request than the real (internal) randmax is
- * - Implement LCG
- * - Implement a real-random source? (via internet, and/or /dev/urandom?)
- * - Can lrand48 be thread-safe?
- * - Is random() useful sometimes?
- * - Which system algorithms are available, maybe name them after real
- * algorithm by compile-time detection?
- * - Get this to compile :-)
- */
#ifndef PHP_RAND_H
#define PHP_RAND_H
#include <stdlib.h>
-/* FIXME: that '_php_randgen_entry' needed, or not? */
-typedef struct _php_randgen_entry {
- void (*srand)(long seed TSRMLS_DC);
- long (*rand)(TSRMLS_D);
- long randmax;
- char *ini_str;
-} php_randgen_entry;
-
-/* an ARRAY of POINTERS, not vice versa */
-extern php_randgen_entry *php_randgen_entries[];
-
-#define PHP_RANDGEN_ENTRY(which, nsrand, nrand, nrandmax, nini_str) { \
- php_randgen_entries[which] = emalloc(sizeof(php_randgen_entry)); \
- php_randgen_entries[which]->srand = nsrand; \
- php_randgen_entries[which]->rand = nrand; \
- php_randgen_entries[which]->randmax = nrandmax; \
- php_randgen_entries[which]->ini_str = nini_str; \
-}
-
-/* Define random generator constants */
-#define PHP_RAND_SYS 0
-#define PHP_RAND_LRAND48 1
-#define PHP_RAND_MT 2
-#define PHP_RAND_LCG 3
-
-#define PHP_RAND_DEFAULT PHP_RAND_MT
-
-/* how many there are */
-#define PHP_RAND_NUMRANDS 4
-
-/* Proto's */
-PHP_RINIT_FUNCTION(rand);
-PHP_MINIT_FUNCTION(rand);
-PHP_MINIT_FUNCTION(rand_mt);
-PHP_MINIT_FUNCTION(rand_sys);
-
-PHP_FUNCTION(srand);
-PHP_FUNCTION(rand);
-PHP_FUNCTION(getrandmax);
-PHP_FUNCTION(mt_srand);
-PHP_FUNCTION(mt_rand);
-PHP_FUNCTION(mt_getrandmax);
-
-PHPAPI long php_rand(TSRMLS_D);
-PHPAPI long php_rand_range(long min, long max TSRMLS_DC);
-PHPAPI double php_drand(TSRMLS_D);
-PHPAPI long php_randmax(TSRMLS_D);
+#ifndef RAND_MAX
+#define RAND_MAX (1<<15)
+#endif
+
+#if HAVE_LRAND48
+#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 */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: fdm=marker
- * vim: sw=4 ts=4 tw=78
- */