Closed Error323 closed 6 years ago
Because it’s much faster?
I'm guessing because it's good enough and very fast. Probably speed is a big consideration, though I wonder if RNGtion is an actual performance bottleneck or not.
AFAIK we only use random in three places.
None of these require highly random numbers and none of these have high performance requirements (2 is called ~1000 times per second), so pretty much any PRNG will do IMO
Agreed @sethtroisi, since you went over Random and Timing with the std lib. Greatly improving their simplicity I was wondering what made you keep xoroshiro :-)
@Error323 I always aim for the smallest possible change (minimizing the number of possible objections and hangups in the Pull Request). When I worked on random I said "that can go in a later pull request" and never returned to look at it.
It's faster and much better (in terms of randomness) than mt19937_64. The rng in the C++11 stdlib are just terrible compared to modern state of the art, and there's seeding issues with the stdlib interfaces too.
Also having a fast RNG is pretty handy for Monte Carlo playouts (i.e. it's a leftover).
I wrote a random library few years a go for my GA projects that uses /var/urandom on a linux system. I could 'port' to C++14 and then have CMake link it if a /dev/urandom device is found, so at least the Linux systems (and maybe Mac) have a fast RNG.
We already use /dev/urandom for seeding on Linux through https://github.com/gcp/leela-zero/blob/bdc3abe7bbd08d1c3a4d5e5ad2068ea81c99237e/src/GTP.cpp#L101
In any case such a call is much slower (userspace<>kernel transition) than just generating the numbers ourselves. xoroshiro is state of the art and we're not doing cryptography.
I see, I had assumed mersenne twister was quite allright. Just looked up the differences and xoroshiro128+ is indeed far superior. http://xoroshiro.di.unimi.it/
Anyway I realize this is not a very relevant issue for the project, I think it can be closed now. Thanks!
I was wondering why the xoroshiro128+ random generator was implemented in Random.cpp? Wouldn't e.g. the std::mt19937_64 suffice?