summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-12-26 16:36:31 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-12-26 16:36:31 -0200
commitfada8efd017c9834607a8d634d2f2a2c0c5d5289 (patch)
treefd3e7c10ec4ac3f96062abcea89b1da3d1ab0870
parentd916487d7c1f620dc7844ca4febfd51f8708a7be (diff)
downloadlua-github-fada8efd017c9834607a8d634d2f2a2c0c5d5289.tar.gz
"rand()", in SunOS, may return values bigger than "RAND_MAX"...
-rw-r--r--lmathlib.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/lmathlib.c b/lmathlib.c
index 13c74a0a..ad462535 100644
--- a/lmathlib.c
+++ b/lmathlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lmathlib.c,v 1.6 1997/11/28 12:39:22 roberto Exp roberto $
+** $Id: lmathlib.c,v 1.7 1997/12/09 13:35:19 roberto Exp roberto $
** Lua standard mathematical library
** See Copyright Notice in lua.h
*/
@@ -145,8 +145,10 @@ static void math_max (void)
static void math_random (void)
{
+ /* the '%' is needed because on some sistems (SunOS!) "rand()" may */
+ /* return a value bigger than RAND_MAX... */
+ double r = (double)(rand()%RAND_MAX) / (double)RAND_MAX;
double l = luaL_opt_number(1, 0);
- double r = (double)rand() / (double)RAND_MAX;
if (l == 0)
lua_pushnumber(r);
else