I‘m reading the C++ reference for rand() which returns a randomly distributed number in a specific range. For getting random numbers in the range 0-99, one can simply use a modulo operation:
int random0to99 = rand() % 100; In the reference, it is additionally stated that:
Notice though that this modulo operation does not generate uniformly distributed random numbers in the span (since in most cases this operation makes lower numbers slightly more likely).
Why? Why isn‘t rand() % 100 uniformly distributed when rand() is?
rand() % 100would be distributed ifRAND_MAXwas150randcan be of high quality, but implementations have traditionally been pretty poor. I suspect there's a fear of changing them because of Hyrum's Law, although the concern there could be well-founded. (As a thought experiment, imagine if Minecraft seeds were suddenly completely different; it would piss off a pretty large community.)