3 ms·
Oh? I get perfectly sane results using modulo, as it should if it is actually a completely random number: http://3v4l.org/nIBGT http://3v4l.org/nIBGT
by lucb1e 11y ago
Oh? I get perfectly sane results using modulo, as it should if it is actually a completely random number: http://3v4l.org/nIBGT http://3v4l.org/nIBGT
- sarciszewski 11y agoYou found the exception! Congratulations! You're using a bucket size which is a power of 2. A random byte fits on the interval of [0, 255] which is evenly distributed modulo 256, which if you reduce mod 2^N for 1 < N < 8 will still produce a uniform distribution. If you copied my JS code into your console and changed the 54 to 64 the bias evaporates. Hooray :D However, for arbitrary ranges, you should use an unbiased selection strategy to ensure a uniform distribution. http://3v4l.org/EgfPR http://3v4l.org/EgfPR - notice 0 is significantly more common than the other values when reduced mod 17 http://3v4l.org/LXmKq http://3v4l.org/LXmKq - same with mod 15 https://defuse.ca/generating-random-passwords.htm https://defuse.ca/generating-random-passwords.htm