2 ms·
(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
by andreareina 8y ago
(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.
- bjoli 8y agoI 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.