Skip to content

Commit

Permalink
stop using rand.Seed() (#385)
Browse files Browse the repository at this point in the history
From math/rand/rand.go:
As of Go 1.20 there is no reason to call Seed with a random value.
  • Loading branch information
mangalaman93 authored Aug 4, 2024
1 parent ff87317 commit c783199
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ttl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 1 addition & 3 deletions z/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
3 changes: 0 additions & 3 deletions z/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit c783199

Please sign in to comment.