This commit is contained in:
Mechiel Lukkien
2023-01-30 14:27:06 +01:00
commit cb229cb6cf
1256 changed files with 491723 additions and 0 deletions

22
mox-/rand.go Normal file
View File

@ -0,0 +1,22 @@
package mox
import (
cryptorand "crypto/rand"
"encoding/binary"
"fmt"
mathrand "math/rand"
)
// NewRand returns a new PRNG seeded with random bytes from crypto/rand.
func NewRand() *mathrand.Rand {
return mathrand.New(mathrand.NewSource(cryptoRandInt()))
}
func cryptoRandInt() int64 {
buf := make([]byte, 8)
_, err := cryptorand.Read(buf)
if err != nil {
panic(fmt.Errorf("reading random bytes: %v", err))
}
return int64(binary.LittleEndian.Uint64(buf))
}