Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I choose parameters for a smaller-than-standard std::mersenne_twister_engine?

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

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

std::mersenne_twister_engine has a large number of parameters. It's a bit scary.

For my purposes, a period on the order of billions is sufficient. I've heard of TinyMT, that may be appropriate but can't see how to implement it as a template specialization.

How should I choose the parameters? I suspect it will break badly if I merely reduce the "state size" parameter to a few words.

I would consider using a different engine entirely but, apart from tolerating a moderate period, I don't want to sacrifice the quality of statistical randomness. Artefacts such as the below (for linear congruentals) are unacceptable.

enter image description here

like image 506
spraff Avatar asked Nov 10 '22 16:11

spraff


1 Answers

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

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

They are both statistically better than MT, the only disadvantage being small(er) period, but it is ok with you as far as I can see

like image 77
Severin Pappadeux Avatar answered Nov 15 '22 04:11

Severin Pappadeux