• In fairness this is such an easy mistake most rng libraries include random in range functions nowadays.

    That said the only place this kind of bias matters is gambling (because gambling games are not designed around powers of two), every other environment where the bias matters are place cryptographic security properties are required in which case the APIs used are the bulk “fill a buffer” ones. Which you should be using - the majority of random() style functions are not guaranteed to be cryptographically secure and don’t necessarily guarantee that they even can produce every number in their output range - I recall there being a few where even internally to the rng they didn’t cover [0,2^maxbits)


    score 1 · canonical