cvs: php3 /functions/ rand.c

From: Date: Mon, 22 May 2000 17:01:50 +0000
Subject: cvs: php3 /functions/ rand.c
Groups: php.dev 
Request: Send a blank email to php-dev+get-19229@lists.php.net to get a copy of this message
hholzgra Mon May 22 19:01:50 2000 EDT Modified files: /php3/functions rand.c Log: mt_rand() divided by RAND_MAX instead of MT_RAND_MX on some plattforms theese are different (eg. win32) this had been fixed in PHP4 but not PHP3 Index: php3/functions/rand.c diff -u php3/functions/rand.c:1.37 php3/functions/rand.c:1.38 --- php3/functions/rand.c:1.37 Thu Mar 2 17:00:32 2000 +++ php3/functions/rand.c Mon May 22 19:01:50 2000 @@ -30,7 +30,7 @@ | Based on code from: Shawn Cokus <Cokus@math.washington.edu> | +----------------------------------------------------------------------+ */ -/* $Id: rand.c,v 1.37 2000/03/02 16:00:32 bjh Exp $ */ +/* $Id: rand.c,v 1.38 2000/05/22 17:01:50 hholzgra Exp $ */ #include <stdlib.h> @@ -107,6 +107,8 @@ #define loBits(u) ((u) & 0x7FFFFFFFU) /* mask the highest bit of u */ #define mixBits(u, v) (hiBit(u)|loBits(v)) /* move hi bit of u to hi bit of v */ +#define MT_RAND_MAX 2147483647 + static uint32 state[N+1]; /* state vector + 1 extra to not violate ANSI C */ static uint32 *next; /* next random value is computed from here */ static int left = -1; /* can *next++ this many times before reloading */ @@ -352,7 +354,7 @@ /* see the comment in the php3_rand() function about this ugly algorithm */ if (p_min && p_max) { /* implement range */ return_value->value.lval = p_min->value.lval + - (int)((double)(p_max->value.lval - p_min->value.lval + 1) * return_value->value.lval/(PHP_RAND_MAX+1.0)); + (int)((double)(p_max->value.lval - p_min->value.lval + 1) * return_value->value.lval/(MT_RAND_MAX+1.0)); } } /* }}} */ @@ -375,7 +377,7 @@ * Melo: it could be 2^^32 but we only use 2^^31 to maintain * compatibility with the previous php3_rand */ - return_value->value.lval = 2147483647; /* 2^^31 */ + return_value->value.lval = MT_RAND_MAX; /* 2^^31 */ } /* }}} */

« previous php.dev (#19229) next »