PRNG in Math library

Just out of interest, what PRNG does Lua use?

You can see math.random here or in the Corona source. It just calls into the C runtime; a linear congruential generator is pretty typical.

There’s been some revision of this in 5.4, e.g. see this thread.

Interesting, I found a Lua implementation of Mersenne twister, unlike LCG has a very long period.

https://github.com/linux-man/randomlua/blob/master/randomlua.lua

if you want a pure-lua mersenne twister, i might suggest this one instead, since it will pass validation - ie, using same seed, will generate an output sequence identical to the reference mt19937ar.out.  (the one you linked offers no way to validate that it’s a correct implementation, and a poor/flawed implementation of a good prng = a poor/flawed prng)

note that while mt is quite “good”, it’s ridiculously long period is not a significant factor of its overall “goodness”.  that is, if your primary need is a very long period then mt stands out, more than it would if your primary need were “indistinguishable from true randomness”, for example.

the xoroshiro family are simpler and in many ways “gooder” than mt.

Thanks, I’ll use that.

You can see math.random here or in the Corona source. It just calls into the C runtime; a linear congruential generator is pretty typical.

There’s been some revision of this in 5.4, e.g. see this thread.

Interesting, I found a Lua implementation of Mersenne twister, unlike LCG has a very long period.

https://github.com/linux-man/randomlua/blob/master/randomlua.lua

if you want a pure-lua mersenne twister, i might suggest this one instead, since it will pass validation - ie, using same seed, will generate an output sequence identical to the reference mt19937ar.out.  (the one you linked offers no way to validate that it’s a correct implementation, and a poor/flawed implementation of a good prng = a poor/flawed prng)

note that while mt is quite “good”, it’s ridiculously long period is not a significant factor of its overall “goodness”.  that is, if your primary need is a very long period then mt stands out, more than it would if your primary need were “indistinguishable from true randomness”, for example.

the xoroshiro family are simpler and in many ways “gooder” than mt.

Thanks, I’ll use that.