3 ms·
How does the seed value get created randomly? I presume it doesn't use the same global random number generator, since that would still make it deterministic?
by SpaghettiX 4y ago
How does the seed value get created randomly? I presume it doesn't use the same global random number generator, since that would still make it deterministic?
- deleted 4y ago[deleted]
- Scaevolus 4y agoIt's seeded using the CPU tick counter (RDTSC on x86-64), which is sufficiently random (billions of increments per second of uptime!) for this. https://cs.opensource.google/go/go/+/refs/tags/go1.20:src/math/rand/rand.go;l=415 https://cs.opensource.google/go/go/+/refs/tags/go1.20:src/ma... https://cs.opensource.google/go/go/+/release-branch.go1.20:src/runtime/stubs.go;l=132 https://cs.opensource.google/go/go/+/release-branch.go1.20:s... https://cs.opensource.google/go/go/+/release-branch.go1.20:src/runtime/proc.go;l=827 https://cs.opensource.google/go/go/+/release-branch.go1.20:s... https://cs.opensource.google/go/go/+/master:src/runtime/asm_amd64.s;l=1078 https://cs.opensource.google/go/go/+/master:src/runtime/asm_...
- cpeterso 4y agoI’m surprised they don’t just seed using /dev/urandom (or the platform specific analogue).