ref: 4a7ffbf2ed517f7d8b996875dc4753444b1e05d2
parent: 339abac8ab1ca47db97bc5c7da08065418503e92
author: Tor Andersson <tor.andersson@artifex.com>
date: Mon Nov 10 07:19:22 EST 2014
Fix bug in Math.random(). Return value should be 0 <= x < 1. Fix typo and divide by RAND_MAX + 1.0 to avoid integer overflow.
--- a/jsmath.c
+++ b/jsmath.c
@@ -66,7 +66,7 @@
static void Math_random(js_State *J)
{
- js_pushnumber(J, (double)rand() / (RAND_MAX - 1));
+ js_pushnumber(J, rand() / (RAND_MAX + 1.0));
}
static void Math_round(js_State *J)