lua-users home
lua-l archive

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


On Tue, Sep 06, 2005 at 09:56:50PM -0500, Graham Wilson wrote:
> math.random() doesn't return anything useful when lua_Number is int. I
> think it makes sense for at least the one and two argument versions to
> return something useful, and the attached patch attempts to do this.

Although slightly off-topic, using math.random() is usually ill-advised.
Almost all random number generators in system libraries suffer from
low-periodicity or worse.  Numerical Recipes for C Sec. 7.1 (available
freely on the web) has a good explanation of this:

http://www.library.cornell.edu/nr/bookcpdf/c7-1.pdf

I know there's at least one Mersenne-Twister implementation out there (I
think it's in one of lhf's libraries), and the GNU Scientific Library,
although under GPL, has a slew of good rng's.  You'll probably be better
off using a reliable rng and rolling your own wrapper than using
math.random().  This is especially true of anything that requires a
modicum of statistical significance.

Cheers!

-- 
Shannon Stewman         | Let us walk through the waning night,
Caught in a whirlpool,  | As dawn-rays tickle our toes, the dew soothes
A quartering act:       | Our blistered soles, and damp bones stir
Solitude or society?    | As crimson cracks under the blue-grey sky.