github.com/cozy/cozy-stack@v0.0.0-20240603063001-31110fa4cae1/pkg/utils/rand.go (about) 1 package utils 2 3 import ( 4 "io" 5 "math/rand" 6 ) 7 8 type randGen struct { 9 rand.Rand 10 } 11 12 // NewSeededRand returns a random bytes reader initialized with the given seed. 13 func NewSeededRand(seed int64) io.Reader { 14 src := rand.NewSource(seed) 15 return &randGen{ 16 Rand: *rand.New(src), 17 } 18 } 19 20 func (r *randGen) Read(p []byte) (n int, err error) { 21 for i := 0; i < len(p); i++ { 22 p[i] = byte(r.Rand.Intn(255)) 23 } 24 return len(p), nil 25 }