May 2, 2018

Understanding Modulo Bias

It is often said that this code: unsigned int randomNumber = rand() % k; is a bad idea, at least if you are expecting a uniform distribution. I’m going to try and explore this topic in a more formal fashion than I have seen so far. The reason why it is bad is pretty elementary and easy to understand: imagine you have a random generator that outputs values between \(0\) and \(9\) (i.
Read more

© Julian Bayardo Spadafora 2015-2020

Back to Top