Re:Writing a Simple Password Generator in Racket
by bjoli on Friday March 08, 2019 @06:31AM
(#19336668)
I made this: https://pastebin.com/kQhKexEd in 5 minutes. It is however slightly off with the random distribution since I am only doing a simple remainder.
[ Parent
| on HN ]
Re:Writing a Simple Password Generator in Racket
by andreareina on Friday March 08, 2019 @07:44AM
(#19337022)
(let ((byte (remainder (get-u8 urandom) size)))
is skewed if size isn't a power of 2. What you should do is mod by the next-largest power of 2 (e.g. if size is 82, mod by 128). Then if the result is in-range use it, otherwise discard and reroll.
Re:Writing a Simple Password Generator in Racket
by bjoli on Friday March 08, 2019 @07:48AM
(#19337044)
I just edited the comment before I saw your answer. I realised my mistake and wanted to sink through the earth. Everyone has brain farts, I guess.
What I ended up doing was limiting the charset size to 256 a maximum of characters, and then discarding any value that is larger than the current charset.