News for hackers. Stuff that matters.
Re:You'll regret using natural keys by whyever on Wednesday June 05, 2024 @04:21AM (#40582619)
Please don't use % to generate integers from a range, it's not uniform, which can be disastrous if you rely on your numbers not being predictable. You can use crypto.randomInt instead.
Re:You'll regret using natural keys by CodesInChaos on Wednesday June 05, 2024 @04:07PM (#40589894)
That is definitely an improvement, but I find that concern a bit exaggerated.

If all you need is unpredictability, a minor bias is sub-optimal but not disastrous. The 256 % 62 bias used here should reduce the min-entropy per character by 5%. And you can easily minimize the bias by using larger integer than a single 8-bit byte. There few algorithms where minor biases cause a disaster, like DSA.