Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed randomNumber's frontwards bias (#26)
Before in randomNumber return crypto.randomBytes(1)[0] % max; was used to generate the random number. Using modulo at the end does lead to a bias in the probability distribution of the generated characters if the character count does not divide 256. E.g. if using randomNumber(255) the number 0 is twice as likely as all other numbers and thus the character 'a' will appear much more frequently. The fix is to discard the random value if it is above the highest mulitple of the character count that is not greater than 256.
- Loading branch information