lua-users home
lua-l archive

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


On Fri, Mar 23, 2018 at 5:24 PM, Albert Chan <albertmcchan@yahoo.com> wrote:
> You mean just two math.random(0) (128 bits) can predict the next one ?

No, if you see the least significant bit of 128 consecutive calls to
math.random, then you can predict the least significant bit of every
call from there on out.

> Reading http://xoroshiro.di.unimi.it, it seems linearity is not that bad.
> BUT, why Vigna say never use last 2 bits to build double ?  I am confused.

The lower-order bits are less random than the higher-order bits, and
this is true of many RNG designs. If you want a coin flip, pick a bit
out of the middle instead of taking the lowest bit. If you want to
construct a floating-point value, the lowest two bits have enough of a
correlation that you get especially bad results.

/s/ Adam