[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
**Subject**: **[proposal] Concerns about math.random**
**From**: Jeremy Ong <jeremycong@...>
**Date**: Sat, 22 Mar 2014 02:04:24 -0700

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
(http://en.wikipedia.org/wiki/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