From 4fbb2531b3e60094e760e30fffbd9c8b2d67a238 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 30 Dec 1998 19:23:26 -0200 Subject: [PATCH] =?UTF-8?q?don=C2=B4t=20need=20the=20"+1",=20the=20"%"=20i?= =?UTF-8?q?s=20enough=20to=20garantee=20r<1.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lmathlib.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lmathlib.c b/lmathlib.c index 63a9c1f9..21bf9308 100644 --- a/lmathlib.c +++ b/lmathlib.c @@ -1,5 +1,5 @@ /* -** $Id: lmathlib.c,v 1.12 1998/12/28 13:44:54 roberto Exp roberto $ +** $Id: lmathlib.c,v 1.13 1998/12/30 17:22:17 roberto Exp roberto $ ** Lua standard mathematical library ** See Copyright Notice in lua.h */ @@ -154,9 +154,9 @@ static void math_max (void) static void math_random (void) { - /* the '%' is needed because on some systems (SunOS!) "rand()" may - return a value bigger than RAND_MAX... */ - double r = (double)(rand()%RAND_MAX) / ((double)RAND_MAX+1.0); + /* the '%' avoids the (rare) case of r==1, and is needed also because on + some systems (SunOS!) "rand()" may return a value bigger than RAND_MAX */ + double r = (double)(rand()%RAND_MAX) / (double)RAND_MAX; int l = luaL_opt_int(1, 0); if (l == 0) lua_pushnumber(r);