lua-users home
lua-l archive

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

> -----Original Message-----
> From: [] On
> Behalf Of Jeremy Ong
> Sent: zaterdag 22 maart 2014 10:04
> To: Lua mailing list
> Subject: [proposal] Concerns about math.random
> Looking at the source code for math.random and math.randomseed, I
> can't help but wonder if the user would be better off not using those
> functions. The main issue is that random numbers generated from it
> will be nonuniform. Among many programming circles, rand() is
> considered harmful.
> For those that wonder if the small amount of nonuniformity is
> relevant, I would say it can be surprisingly significant. Of course
> this is significant for people doing statistical analysis or monte
> carlo methods but this sort of bias introduced to RNG would be lethal
> in: scripting a rendering engine, distributing loot drops for a game,
> randomizing enemies, etc.
> I know C++ is not everyone's cup of tea, but it should be telling that
> rand() is to be deprecated in C++14 in favor of <random>, precisely
> for this reason.
> My recommendation is an implementation of the mersenne twister
> ( MT is known to be
> highly performant and produce high quality random numbers. With the
> new bit shift operators this is a lot more doable. If there's
> interest, I may try to provide a reference implementation for people
> to try.
> Thoughts?
> Cheers,
> Jeremy

I think its limited because of ANSI compilers. A mersenne twister is available as the 'lrandom' library by lhf [1]. A while ago I ran into some limitations myself when using a too large randomseed, see this thread [2]