4 ms·
The example in previous versions of the Go math/rand package suggested using time.Now().UnixNano() to seed the RNG source since that's essentially a random int6
by Brentward 4y ago
The example in previous versions of the Go math/rand package suggested using time.Now().UnixNano() to seed the RNG source since that's essentially a random int64.
- morepork 4y agoIt's a reasonable choice, and will be unique for most program runs, but it's not exactly random
- ihatepython 4y agoPhilosophically, there is no such thing as a random number
- dharmab 4y agoThere are ways to get truly random numbers into a computer. Certain phenomena are theorized to be fundamentally random, and can be used as inputs to hardware. https://en.m.wikipedia.org/wiki/Hardware_random_number_generator https://en.m.wikipedia.org/wiki/Hardware_random_number_gener...
- majewsky 4y agoThe sound of conviction in your first sentence does not match the "theorized to be" in the second sentence. I recommend that you don't bring a "for all intents and purposes" to a "philosophically" fight. ;)
- mseepgood 4y agoHowever, the universe is based on randomness at its quantum core.
- morepork 4y agoOr perhaps the universe is a simulation whose prng was seeded with 1 just like golang does 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.
- runarberg 4y agoIs it though? I’m merely a layperson here so I might be grossly misunderstanding, but I didn’t know determinism had been ruled out by quantum physics. I was under the impression that quantum phenomena was best described using probability. That means there might be an element of true randomness going on, but also that these systems are so chaotic that an observation is going to have some noise, regardless of any randomness at the core. The latter says nothing about how random things are, merely that they appear with some probability, they could be completely deterministic for all we know.
- panzi 4y agoTo get cryptographically grade randomness you can use one of these C functions: *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 https://github.com/panzi/portable_get_random*
- zaphirplane 4y agoWhat a fascinating insight to the naming conventions of the different OS. Mac the long descriptive. BSD short and accurate. Linux short details are for specs. Fuchisa the functional HW reference ? What is that
- panzi 4y agoFuchsia is an open-source capability-based operating system developed by Google. —Wikipedia