It's the kind of "bug" that doesn't manifest until your data is thoroughly boned.
How do I make sure I'm passing a random seed to my RNG?
(I must be missing something here)
math/rand provides global functions using a global RNG, as well as the ability to instantiate your own RNG and call functions (methods) on that RNG.
Previously, the global functions all used a seed of 1, which made them generate identical sequences. Now, they use random seed, which makes them less-easily predictable (though still predictable).
There is no change to the self-instantiated RNGs.
> How do I make sure I'm passing a random seed to my RNG?
With the change, using the global functions in Go 1.20+ is the same as instantiating your own RNG with a random seed.
https://en.m.wikipedia.org/wiki/Hardware_random_number_gener...
Maybe we're in the first batch of simulations, and the tester came along and asks why they're all identical. The cosmic coder then realises that they forgot to call the function to seed the prng.
*BSD, newer macOS, and GNU libc: int getentropy(void *buffer, size_t length);
Linux 3.19+: ssize_t getrandom(void *buf, size_t buflen, unsigned int flags);
iOS and macOS 10.7+: int SecRandomCopyBytes(SecRandomRef, size_t, uint8_t *);
Fuchsia: void zx_cprng_draw(void* buffer, size_t buffer_size);
Any *nix: Read from "/dev/random" (or "/dev/urandom" under the assumption that your system has already enough entropy).
Windows: There are different functions/libraries depending on the Windows version and some of them are a complicated multi-step mess.
Some time ago I wrote a C library that abstracts that away just for fun: https://github.com/panzi/portable_get_random*
This change only affects the global RNG. Creating a new RNG has always required setting a seed
Amusingly, I submitted a patch for this some years ago, and it was rejected on the grounds that callers might depend on the specific sequence of numbers outputted by the global RNG using the default seed, which could break the compatibility promise.
Now that that's been deemed a non-issue, I might resubmit.
Given randomness requires a seed and UNIX's ISO standard defines the default seed as 0, it's rational from a comp sci perspective to expect to supply a seed to produce a random number.
However, due to how ergonomic and safe high level languages are today, you don't need to be a computer scientist to make a highly available, beautiful and robust application. As such, the inhabitants of the application development world are considerably less concerned with such details and want, when they call a thing, it gives an intuitive result.
It's important that tool makers consider their users when creating APIs. Supplying a seed to a function called "getRandomNumber" might be obvious to a C programmer, but not obvious to a JavaScript programmer looking to use Go to improve the performance of their back end service.