Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getRandomSymbol is slightly biased #6

Closed
danstiner opened this issue Jan 21, 2018 · 0 comments
Closed

getRandomSymbol is slightly biased #6

danstiner opened this issue Jan 21, 2018 · 0 comments
Labels

Comments

@danstiner
Copy link
Owner

danstiner commented Jan 21, 2018

Currently symbols are chosen from an alphabet by just modding a uin32 down to the length of the alphabet, this can introduce bias for non-power-of-two alphabet sizes of about 2^-32 - 2^-log2(|alphabet|) or about 1/2^21 for a wordlist with about two thousand words. This is small but not entirely negligible and should be fixed.

symbol: alphabet[randomValues[0] % alphabet.length],

Relevant reference: https://stackoverflow.com/questions/137783/expand-a-random-range-from-1-5-to-1-7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant