4 cryptorand "crypto/rand"
16// NewPseudoRand returns a new PRNG seeded with random bytes from crypto/rand.
17func NewPseudoRand() *rand {
18 return &rand{Rand: mathrand.New(mathrand.NewSource(CryptoRandInt()))}
21// Read can be called concurrently.
22func (r *rand) Read(buf []byte) (int, error) {
25 return r.Rand.Read(buf)
28// CryptoRandInt returns a cryptographically random number.
29func CryptoRandInt() int64 {
30 buf := make([]byte, 8)
31 _, err := cryptorand.Read(buf)
33 panic(fmt.Errorf("reading random bytes: %v", err))
35 return int64(binary.LittleEndian.Uint64(buf))