Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe to take only a few bits from a number obtained with a Mersenne Twister

I have to work with some code produced by an employee that is now retired, and I have some few strange things concerning random numbers. At some points, he shifted the value returned by a PRNG 10 bits to the right and then use a mask on this value.

I have already seen on the internet that some PRNG have poor randomness properties with some bits in the number they generate (like the last one, simply alternating between 1 and 0), but I've searched if some litterture existed for such problems on the Mersenne Twister, but I haven't found any. Does anyone know something about this ?

like image 958
Loufylouf Avatar asked Nov 22 '22 07:11

Loufylouf


1 Answers

Normally, any bit should be random, this is a property of the Mersenne twister.

However (I do not know MT very deeply) you may have long-term dependence between some bits. It is recommended to use the library functions for setting the integer range, rather than arranging the bits yourself, or you never know the complex properties it may get.

If you use the c++11 standard library, just use std::mt19937 together with std::uniform_int_distribution

like image 112
galinette Avatar answered Dec 17 '22 21:12

galinette