3 ms·
One thing that isn't mentioned in the article is performance. C++ standard PRNG's, on top of all the brokenness listed in the article are very inefficient, esp
by ur-whale 6y ago
One thing that isn't mentioned in the article is performance.
C++ standard PRNG's, on top of all the brokenness listed in the article are very inefficient, especially if you use distributions.
- gnulinux 6y agoI was curious why that'd be the case. I checked GCC's implementation. It seems to be here: https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/bits/uniform_int_dist.h#L238 https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-... Looks like they had to make this very generic, generic enough to account for random number generators that return value in specific ranges. If you have a generator that guarantees to return a uniformly random 32 bit value, it seems much faster to do (r%(max-min)+min) instead.
- brandmeyer 6y agoTaking the modulus of the desired range isn't uniform.
- gnulinux 6y agoThat's true, and obviously so but I never realized it until now. I'm curious why r%(max-min)+min is widespread "common" way of doing this, maybe I just saw it in a few places and never questioned it.
- eska 6y agoSomewhere in the footnotes he mentions that Microsoft considers changing the implementation of its uniform int distribution for performance reasons (as a supporting argument for lack of portability).