From 6f614bb84341b22c0ad2de3343b376cf09ee5e09 Mon Sep 17 00:00:00 2001 From: Aman Mangal Date: Wed, 31 Jul 2024 07:13:33 +0530 Subject: [PATCH] stop using rand.Seed() From math/rand/rand.go: As of Go 1.20 there is no reason to call Seed with a random value. --- ttl.go | 2 +- z/allocator.go | 4 +--- z/buffer_test.go | 3 --- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/ttl.go b/ttl.go index 8ccb1266..08e77c16 100644 --- a/ttl.go +++ b/ttl.go @@ -143,7 +143,7 @@ func (m *expirationMap[V]) cleanup(store store[V], policy policy[V], onEvict fun for key, conflict := range keys { expr := store.Expiration(key) // Sanity check. Verify that the store agrees that this key is expired. - if store.Expiration(key).After(now) { + if expr.After(now) { continue } diff --git a/z/allocator.go b/z/allocator.go index eae0f834..dc272f68 100644 --- a/z/allocator.go +++ b/z/allocator.go @@ -56,9 +56,7 @@ func init() { allocs = make(map[uint64]*Allocator) // Set up a unique Ref per process. - rand.Seed(time.Now().UnixNano()) - allocRef = uint64(rand.Int63n(1<<16)) << 48 //nolint:gosec // cryptographic precision not needed - + allocRef = uint64(rand.Int63n(1<<16)) << 48 calculatedLog2 = make([]int, 1025) for i := 1; i <= 1024; i++ { calculatedLog2[i] = int(math.Log2(float64(i))) diff --git a/z/buffer_test.go b/z/buffer_test.go index 361bda73..2531f1d4 100644 --- a/z/buffer_test.go +++ b/z/buffer_test.go @@ -24,13 +24,11 @@ import ( "math/rand" "sort" "testing" - "time" "github.com/stretchr/testify/require" ) func TestBuffer(t *testing.T) { - rand.Seed(time.Now().Unix()) const capacity = 512 buffers := newTestBuffers(t, capacity) @@ -61,7 +59,6 @@ func TestBuffer(t *testing.T) { } func TestBufferWrite(t *testing.T) { - rand.Seed(time.Now().Unix()) const capacity = 32 buffers := newTestBuffers(t, capacity)