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 difference between rand.Read() and rand.Rand.Read()
To be a thread safe:
- Will it panic when
Readis called concurrently? - Will it keep the random sequence when called concurrently? Or can duplicates be given to concurrent callers?
>Solution :
rand.Readerfromcrypto/randmust 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 synchronized its use between packages.rand.Readfromcrypto/randis safe because therand.Readeris safe, and there is no other shared state.