The source of math/rand.Rand states Read is not thread safe (when sharing a source). What about crypto/rand? The source states it uses getrandom(2) or /dev/urandom, but it is unclear what happens with concurrent calls.
Update: comments have helped clarify the distinction
crypto/rand.Reader.Read(b []byte)
crypto/rand.Read(b []byte)
To be a thread safe:
Read is called concurrently?rand.Reader from crypto/rand must be safe for concurrent access, because it is defined as "a global, shared instance of a cryptographically secure random number generator". There would be no way to synchronize its use between packages.rand.Read from crypto/rand is safe because the rand.Reader is safe, and it does not access any other shared state.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With