lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Wed, Sep 07, 2005 at 10:14:20AM +0700, Antero Vipunen wrote:
> Graham Wilson wrote:
> >int r = rand()%RAND_MAX;
> >lua_pushnumber(L, (lua_Number)r / (lua_Number)RAND_MAX);  /* Number 
> >between 0 and 1 */
> Simple mathematics shows us that this will always push 0. Because:
> 0 <= r < RAND_MAX and so r/RAND_MAX == 0.

True, but we can't really expect more when the function returns an int.

I suppose math.random with no arguments could be changed to return just
r when lua_Number is an int, but I'm not sure if that would be a really
great idea.