diff options
-rw-r--r-- | manual.tex | 10 | ||||
-rw-r--r-- | mathlib.c | 8 |
2 files changed, 12 insertions, 6 deletions
@@ -1,4 +1,4 @@ | |||
1 | % $Id: manual.tex,v 2.10 1997/07/02 17:09:48 roberto Exp roberto $ | 1 | % $Id: manual.tex,v 2.11 1997/07/04 22:35:38 roberto Exp roberto $ |
2 | 2 | ||
3 | \documentstyle[fullpage,11pt,bnf]{article} | 3 | \documentstyle[fullpage,11pt,bnf]{article} |
4 | 4 | ||
@@ -38,7 +38,7 @@ Waldemar Celes | |||
38 | \tecgraf\ --- Computer Science Department --- PUC-Rio | 38 | \tecgraf\ --- Computer Science Department --- PUC-Rio |
39 | } | 39 | } |
40 | 40 | ||
41 | \date{\small \verb$Date: 1997/07/02 17:09:48 $} | 41 | \date{\small \verb$Date: 1997/07/04 22:35:38 $} |
42 | 42 | ||
43 | \maketitle | 43 | \maketitle |
44 | 44 | ||
@@ -2085,8 +2085,10 @@ Both can be used with an unlimited number of arguments. | |||
2085 | The functions \verb|random| and \verb|randomseed| are interfaces to | 2085 | The functions \verb|random| and \verb|randomseed| are interfaces to |
2086 | the simple random generator functions \verb|rand| and \verb|srand|, | 2086 | the simple random generator functions \verb|rand| and \verb|srand|, |
2087 | provided by ANSI C. | 2087 | provided by ANSI C. |
2088 | The function \verb|random| returns pseudo-random numbers in the | 2088 | The function \verb|random|, when called without arguments, |
2089 | range \Math{[0,1)}. | 2089 | returns a pseudo-random real number in the range \Math{[0,1)}. |
2090 | When called with a number \Math{n}, | ||
2091 | returns a pseudo-random integer in the range \Math{[1,n]}. | ||
2090 | 2092 | ||
2091 | 2093 | ||
2092 | \subsection{I/O Facilities} \label{libio} | 2094 | \subsection{I/O Facilities} \label{libio} |
@@ -3,7 +3,7 @@ | |||
3 | ** Mathematics library to LUA | 3 | ** Mathematics library to LUA |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_mathlib="$Id: mathlib.c,v 1.24 1997/06/09 17:30:10 roberto Exp roberto $"; | 6 | char *rcs_mathlib="$Id: mathlib.c,v 1.25 1997/06/19 18:03:04 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
9 | #include <math.h> | 9 | #include <math.h> |
@@ -171,7 +171,11 @@ static void math_rad (void) | |||
171 | 171 | ||
172 | static void math_random (void) | 172 | static void math_random (void) |
173 | { | 173 | { |
174 | lua_pushnumber((double)(rand()%RAND_MAX) / (double)RAND_MAX); | 174 | double r = (double)(rand()%RAND_MAX) / (double)RAND_MAX; |
175 | if (lua_getparam(1) == LUA_NOOBJECT) | ||
176 | lua_pushnumber(r); | ||
177 | else | ||
178 | lua_pushnumber((int)(r*luaL_check_number(1)) + 1); | ||
175 | } | 179 | } |
176 | 180 | ||
177 | static void math_randomseed (void) | 181 | static void math_randomseed (void) |