How to choose options for standard std :: mersenne_twister_engine?

I need a C ++ 11 random number generator that is "good enough" and which I can save and restore state to. I want the saved state to be significantly less than 6.6kb or so what this code produces

std::mt19937 rng (1); std::ofstream save ("save.txt"); save << rng; 

std :: mersenne_twister_engine has a large number of parameters. This is a little scary.

For my purposes, a period of the order of billions is enough. I heard about TinyMT, which may be appropriate, but cannot figure out how to implement it as a specialized specialization.

How to choose options? I suspect this will break down a lot if I simply reduce the state size parameter to a few words.

I would consider using another engine entirely, but, not allowing a moderate period, I do not want to sacrifice the quality of statistical randomness. Artifacts such as the following (for linear congruents) are not acceptable.

enter image description here

+6
source share
1 answer

If you do not need a lot of numbers, any decent 64-bit RNG will be good. From the top of my hat, a very good generator would be XorShift64 *, paper http://arxiv.org/abs/1402.6246 , code https://github.com/Iwan-Zotow/xorshift64STAR

Another use case is PCG, "Quadratisch. Praktisch. Gut.", Paper and code at http://www.pcg-random.org/

They are statistically better than MT, the only drawback is the small (er) period, but you are okay, as far as I can see

+1
source

Source: https://habr.com/ru/post/985089/


All Articles