AlpakkaFarmi/keygen

Remove modulo bias

Opened this issue · 0 comments

Use rejection sampling and modulo reduction instead of

output.push(ALPHABET_WORDSFI[r % l]) // TODO: fix biased indexing

Essentially for the length of wordlist l, find the the largest n where l * n still fits in a usize (note: you need to detect the size of usize at compilation time), reject all random samples r above l * n and then accept WORDLIST[r % l].