Justtechjobs.com Find a programming school near you






Online Campus Both


php4-beta | 200004

[PHP4BETA] cvs: /php4/ext/standard rand.c From: Andi Gutmans (andi <email protected>)
Date: 04/22/00

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 <email protected>> |
    +----------------------------------------------------------------------+
  */
-/* $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 */
 }
 /* }}} */
 /*

-- 
PHP 4.0 Beta Mailing List <http://www.php.net/version4/>
To unsubscribe, e-mail: php4beta-unsubscribe <email protected>
For additional commands, e-mail: php4beta-help <email protected>
To contact the list administrators, e-mail: php4beta-admin <email protected>