News for hackers. Stuff that matters.
Re:The definitive guide to “modulo bias” and how to avoid it... by 10000truths on Thursday September 15, 2022 @03:56PM (#32857661)
If you need to generate multiple such random numbers, an alternative way to resolve modulo bias with minimal entropy waste is to batch the random number generation. For example, you can generate 6 random integers in [0, 100) by generating a random integer in [0, 100^6) and performing modulo reductions on the result to get your 6 integers. 100^6 is slightly less than 256^5, so if your RNG works in units of bytes, then you can use 5 bytes to generate 6 integers in [0, 100) instead of 6 bytes.

There are no comments on this comment yet.