shove70 / crypto

A D Library of encryption, decryption, encode, hash, and message digital signatures.
MIT License
32 stars 12 forks source link

Fix bias towards low numbers in `next(min, max)` when `1 + max - min` is not a power of 2 #2

Closed n8sh closed 6 years ago

n8sh commented 6 years ago

The existing implementation just uses modulo, which is fine when 1L + max - min evenly divides 1L + generator.max, but otherwise causes the result to bias towards low numbers.

shove70 commented 6 years ago

Thanks very much!