4 ms·
Interesting article, but one point: > Sadly, the C++11 <random> library is not portable, but the excellent PCG Random library is, so I used the latter. Yes it
by OskarS 5y ago
Interesting article, but one point:
> Sadly, the C++11 <random> library is not portable, but the excellent PCG Random library is, so I used the latter.
Yes it is. std::random_device will not give you a deterministic sequence (obviously!), but the standard PRNGs absolutely will. Check, for instance, std::mt19937, which specifies exactly what the 10,000th value has to be [1].
That's not to say that you shouldn't go with PCG. PCG is a fantastic PRNG. But claiming that the <random> PRNGs are not portable is just FUD.
[1]: https://en.cppreference.com/w/cpp/numeric/random/mersenne_twister_engine https://en.cppreference.com/w/cpp/numeric/random/mersenne_tw...
- jepler 5y agoThe indirectly linked stackoverflow https://stackoverflow.com/questions/14840901/is-the-random-library-in-c11-portable https://stackoverflow.com/questions/14840901/is-the-random-l... goes into more detail: mt19937 is, but distributions (particularly, based on my experience a few years ago, floating point ones) are not. If you have to build your own distribution functions, you may as well base them on a better PRNG than is in the C++ standard.
- OskarS 5y agoIn the context of that sentence though, it doesn’t make any sense. PCG is a PRNG, not a library for generating distributions. In fact, the PCG documentation uses the distributions from <random>: [1]. If people want to use PCG, that’s perfectly fine, it’s a great library. My point is, there’s nothing wrong with the PRNGs in <random>, they work great. Mersenne Twister is not state of the art anymore, but I guarantee you that unless you’re doing something truly insane, neither the throughput nor the statistical properties of MT is gonna be your bottleneck. [1]: https://www.pcg-random.org/using-pcg-cpp.html https://www.pcg-random.org/using-pcg-cpp.html