diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1998-12-30 19:23:26 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1998-12-30 19:23:26 -0200 |
commit | 4fbb2531b3e60094e760e30fffbd9c8b2d67a238 (patch) | |
tree | ace2ba5261ed6e0c256db9f4dd09e1d95780d55a | |
parent | 59f8e6fb7710e46539fb9bf63131b45012bf86ef (diff) | |
download | lua-4fbb2531b3e60094e760e30fffbd9c8b2d67a238.tar.gz lua-4fbb2531b3e60094e760e30fffbd9c8b2d67a238.tar.bz2 lua-4fbb2531b3e60094e760e30fffbd9c8b2d67a238.zip |
don´t need the "+1", the "%" is enough to garantee r<1.
-rw-r--r-- | lmathlib.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lmathlib.c,v 1.12 1998/12/28 13:44:54 roberto Exp roberto $ | 2 | ** $Id: lmathlib.c,v 1.13 1998/12/30 17:22:17 roberto Exp roberto $ |
3 | ** Lua standard mathematical library | 3 | ** Lua standard mathematical library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -154,9 +154,9 @@ static void math_max (void) | |||
154 | 154 | ||
155 | 155 | ||
156 | static void math_random (void) { | 156 | static void math_random (void) { |
157 | /* the '%' is needed because on some systems (SunOS!) "rand()" may | 157 | /* the '%' avoids the (rare) case of r==1, and is needed also because on |
158 | return a value bigger than RAND_MAX... */ | 158 | some systems (SunOS!) "rand()" may return a value bigger than RAND_MAX */ |
159 | double r = (double)(rand()%RAND_MAX) / ((double)RAND_MAX+1.0); | 159 | double r = (double)(rand()%RAND_MAX) / (double)RAND_MAX; |
160 | int l = luaL_opt_int(1, 0); | 160 | int l = luaL_opt_int(1, 0); |
161 | if (l == 0) | 161 | if (l == 0) |
162 | lua_pushnumber(r); | 162 | lua_pushnumber(r); |