From a013dc4ff96360af09e91484284c020606ef1509 Mon Sep 17 00:00:00 2001 From: Chris Martin Date: Mon, 15 Jul 2024 10:53:01 +0100 Subject: [PATCH] Remove random rand (#3790) Signed-off-by: Chris Martin Co-authored-by: Chris Martin --- internal/common/util/rand.go | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 internal/common/util/rand.go diff --git a/internal/common/util/rand.go b/internal/common/util/rand.go deleted file mode 100644 index ff8fd348003..00000000000 --- a/internal/common/util/rand.go +++ /dev/null @@ -1,33 +0,0 @@ -package util - -import ( - "math/rand" - "sync" -) - -// LockedSource is a random source that is uses a mutex to ensure it is threadsafe -type LockedSource struct { - lk sync.Mutex - src rand.Source -} - -func (r *LockedSource) Int63() (n int64) { - r.lk.Lock() - n = r.src.Int63() - r.lk.Unlock() - return -} - -func (r *LockedSource) Seed(seed int64) { - r.lk.Lock() - r.src.Seed(seed) - r.lk.Unlock() -} - -// NewThreadsafeRand Returns a *rand.Rand that is safe to share across multiple goroutines -func NewThreadsafeRand(seed int64) *rand.Rand { - return rand.New(&LockedSource{ - lk: sync.Mutex{}, - src: rand.NewSource(seed), - }) -}