diff options
Diffstat (limited to '')
| -rw-r--r-- | lmathlib.c | 6 |
1 files changed, 4 insertions, 2 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lmathlib.c,v 1.6 1997/11/28 12:39:22 roberto Exp roberto $ | 2 | ** $Id: lmathlib.c,v 1.7 1997/12/09 13:35:19 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 | */ |
| @@ -145,8 +145,10 @@ static void math_max (void) | |||
| 145 | 145 | ||
| 146 | static void math_random (void) | 146 | static void math_random (void) |
| 147 | { | 147 | { |
| 148 | /* the '%' is needed because on some sistems (SunOS!) "rand()" may */ | ||
| 149 | /* return a value bigger than RAND_MAX... */ | ||
| 150 | double r = (double)(rand()%RAND_MAX) / (double)RAND_MAX; | ||
| 148 | double l = luaL_opt_number(1, 0); | 151 | double l = luaL_opt_number(1, 0); |
| 149 | double r = (double)rand() / (double)RAND_MAX; | ||
| 150 | if (l == 0) | 152 | if (l == 0) |
| 151 | lua_pushnumber(r); | 153 | lua_pushnumber(r); |
| 152 | else | 154 | else |
