summaryrefslogtreecommitdiff
path: root/ext/standard/rand.c
diff options
context:
space:
mode:
authorAndi Gutmans <andi@php.net>2000-04-22 15:40:23 +0000
committerAndi Gutmans <andi@php.net>2000-04-22 15:40:23 +0000
commit44908999a8cacfe016a885e645f8a0f6be9ac7ce (patch)
treea292748e6fcc147cfaa474b9c7571f65f4a645ee /ext/standard/rand.c
parentf9cdcc583c82dfeb7b800436c2edaf8be0dff299 (diff)
downloadphp-git-44908999a8cacfe016a885e645f8a0f6be9ac7ce.tar.gz
- Hopefully fix mt_rand() functions under Windows. This patch will effect
all platforms so I hope it's OK.
Diffstat (limited to 'ext/standard/rand.c')
-rw-r--r--ext/standard/rand.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/ext/standard/rand.c b/ext/standard/rand.c
index f93934ad69..9ba1ca9c85 100644
--- a/ext/standard/rand.c
+++ b/ext/standard/rand.c
@@ -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 @@ PHP_FUNCTION(mt_rand)
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 @@ PHP_FUNCTION(mt_getrandmax)
* 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 */
}
/* }}} */
/*