Feat[entropy]: Access shared rand.Rand
This commit is contained in:
parent
a9ce9387ac
commit
3f6dbd7472
@ -39,6 +39,14 @@ func GetOptimizedRand() *rand.Rand {
|
||||
return rand.New(r)
|
||||
}
|
||||
|
||||
// GetSharedRand returns a pointer to our shared optimized rand.Rand which uses crypto/rand to seed a splitmix64 rng.
|
||||
func GetSharedRand() *rand.Rand {
|
||||
getSharedRand.Do(func() {
|
||||
sharedRand = GetOptimizedRand()
|
||||
})
|
||||
return sharedRand
|
||||
}
|
||||
|
||||
// RNGUint32 returns a random uint32 using crypto/rand and splitmix64.
|
||||
func RNGUint32() uint32 {
|
||||
getSharedRand.Do(func() {
|
||||
|
@ -13,7 +13,12 @@ func check[T comparable](zero T, one T, t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_RNG(t *testing.T) {
|
||||
// for coverage
|
||||
sharedRand = GetSharedRand()
|
||||
RandSleepMS(5)
|
||||
sharedRand = nil
|
||||
getSharedRand = &sync.Once{}
|
||||
// - - - - - -
|
||||
if OneInA(1000000) {
|
||||
println(string([]byte{
|
||||
0x66, 0x75, 0x63, 0x6B, 0x68,
|
||||
|
Loading…
Reference in New Issue
Block a user