4 ms·
Just to beat the horse to death, I want to be clear that what I'm asking for isn't much: 1. The default random() call/library should always produce exactly wha
by matthewdgreen 2y ago
Just to beat the horse to death, I want to be clear that what I'm asking for isn't much:
1. The default random() call/library should always produce exactly what it says -- real, secure, unpredictable (pseudo)random numbers.
2. For statistical and non-security applications it's perfectly fine to have a generator of the form random.insecureAndFast(). Or call it whatever you want, the important thing is that the developer make a tiny amount of conscious effort in the process of using it.
3. If you require reproducible and insecure generator, just use approach (2) above and add a seeding function. (Honestly I don't like anything that uses global state, but I don't care as long as it's labeled insecure.)
4. If you require reproducible and secure random numbers, then you have a slightly challenging problem on your hands that is way beyond the scope of this discussion.
For people who don't require secure randomness, the total "cost" of my proposal is something like an extra dozen characters added to your code in a few places -- and if that's too much work for you, then you probably aren't writing reproducible tests or spending a lot of time optimizing for speed. On the flipside, you might save someone a few million dollars when their crappy Bitcoin library uses a dependency that relies on random().
- liontwist 2y agoI think this is a reasonable solution. I also hope we can standardize a random function which takes an integer range of maximum.