A fast alternative to the modulo reduction (2016)
Let&#x27;s say you want a random number from 0 to 5. You can generate a random integer, take the three low order bits (giving you a random number from 0 to 7), and if it&#x27;s more than 5, try again. I just checked and it seems to work well (&quot;bitmask with rejection&quot;): <a href="http:&#x2F;&#x2F;www.pcg-random.org&#x2F;posts&#x2F;bounded-rands.html" rel="nofollow">http:&#x2F;&#x2F;www.pcg-random.org&#x2F;posts&#x2F;bounded-rands.html</a>