[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Math.Random() always returns 0
- From: "Daniel Collins" <daniel.collins@...>
- Date: Wed, 24 May 2006 20:42:41 +0930
> Beric Holt wrote:
> > Does anyone have any suggestions on why this might be happening?
math.random relies on the C standard library function rand(). So I would
check that rand() works as expected.
> Have you configured Lua to use integer math? I seem to remember there
> was a flaw in Lua 5 that stopped random numbers from working properly
> with integer types, and I've not checked to see if it was
> fixed in 5.1.
That's interesting. I am currently using lua with lua_number set to int.
But as part of porting to my system I had to write my own replacements
for the math.random set of functions, and so I never noticed this
problem.
If you need a replacement for rand(), check out the mersenne twister
implementation that Luiz has on his website:
http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/
- DC