4 cryptorand "crypto/rand"
7 mathrand2 "math/rand/v2"
16// NewPseudoRand returns a new PRNG seeded with random bytes from crypto/rand. Its
17// functions can be called concurrently.
18func NewPseudoRand() *rand {
20 if _, err := cryptorand.Read(seed[:]); err != nil {
23 return &rand{rand: mathrand2.New(mathrand2.NewChaCha8(seed))}
26func (r *rand) Float64() float64 {
29 return r.rand.Float64()
32func (r *rand) IntN(n int) int {
38// CryptoRandInt returns a cryptographically random number.
39func CryptoRandInt() int64 {
40 buf := make([]byte, 8)
41 _, err := cryptorand.Read(buf)
43 panic(fmt.Errorf("reading random bytes: %v", err))
45 return int64(binary.LittleEndian.Uint64(buf))