cvs: /php4/ext/standard rand.c

From: Date: Sat, 22 Apr 2000 15:40:53 +0000
Subject: cvs: /php4/ext/standard rand.c
Groups: php.version4 
Request: Send a blank email to php-version4+get-13918@lists.php.net to get a copy of this message
andi Sat Apr 22 08:40:53 2000 EDT Modified files: /php4/ext/standard rand.c Log: - Hopefully fix mt_rand() functions under Windows. This patch will effect all platforms so I hope it's OK. Index: php4/ext/standard/rand.c diff -u php4/ext/standard/rand.c:1.13 php4/ext/standard/rand.c:1.14 --- php4/ext/standard/rand.c:1.13 Sat Feb 19 15:41:21 2000 +++ php4/ext/standard/rand.c Sat Apr 22 08:40:23 2000 @@ -19,7 +19,7 @@ | Based on code from: Shawn Cokus <Cokus@math.washington.edu> | +----------------------------------------------------------------------+ */ -/* $Id: rand.c,v 1.13 2000/02/19 23:41:21 zeev Exp $ */ +/* $Id: rand.c,v 1.14 2000/04/22 15:40:23 andi Exp $ */ #include <stdlib.h> @@ -92,6 +92,9 @@ #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 */ +/* Could be 1<<32 but for some reason it has been used as 1<<31 in the past */ +#define MT_RAND_MAX ((unsigned long)((1<<31)-1)) + static void seedMT(php_uint32 seed BLS_DC) { /* @@ -327,7 +330,7 @@ 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)); + (long)((double)((*p_max)->value.lval - (*p_min)->value.lval + 1) * return_value->value.lval/(MT_RAND_MAX+1.0)); } } /* }}} */ @@ -351,7 +354,7 @@ * Melo: it could be 2^^32 but we only use 2^^31 to maintain * compatibility with the previous php_rand */ - return_value->value.lval = 2147483647; /* 2^^31 */ + return_value->value.lval = MT_RAND_MAX; /* 2^^31 */ } /* }}} */ /*

« previous php.version4 (#13918) next »