4 cryptorand "crypto/rand"
16// NewPseudoRand returns a new PRNG seeded with random bytes from crypto/rand. Its
17// functions can be called concurrently.
18func NewPseudoRand() *rand {
19 return &rand{rand: mathrand.New(mathrand.NewSource(CryptoRandInt()))}
22func (r *rand) Float64() float64 {
25 return r.rand.Float64()
28func (r *rand) Intn(n int) int {
34func (r *rand) Read(buf []byte) (int, error) {
37 return r.rand.Read(buf)
40// CryptoRandInt returns a cryptographically random number.
41func CryptoRandInt() int64 {
42 buf := make([]byte, 8)
43 _, err := cryptorand.Read(buf)
45 panic(fmt.Errorf("reading random bytes: %v", err))
47 return int64(binary.LittleEndian.Uint64(buf))