Skip to content

Commit 51abaa4

Browse files
Juneezeelemire
authored andcommitted
test: use math/rand/v2
We upgraded our minimum Go version in PR #39, so we can use the `math/rand/v2` package too. Reference: https://go.dev/blog/randv2 Signed-off-by: Eng Zer Jun <[email protected]>
1 parent 20a6abb commit 51abaa4

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

binaryfusefilter_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package xorfilter
22

33
import (
44
"fmt"
5-
"math/rand"
5+
"math/rand/v2"
66
"testing"
77

88
"github.com/cespare/xxhash"
@@ -43,9 +43,9 @@ func TestBinaryFuseNBasic(t *testing.T) {
4343
}
4444
keys = keys[:cut]
4545
for trial := 0; trial < 10; trial++ {
46-
rand.Seed(int64(trial))
46+
r := rand.New(rand.NewPCG(uint64(trial), uint64(trial)))
4747
for i := range keys {
48-
keys[i] = rand.Uint64()
48+
keys[i] = r.Uint64()
4949
}
5050
filter, _ = NewBinaryFuse[testType](keys)
5151
for _, v := range keys {
@@ -93,9 +93,9 @@ func TestBinaryFuseNSmall(t *testing.T) {
9393
}
9494
keys = keys[:cut]
9595
for trial := 0; trial < 10; trial++ {
96-
rand.Seed(int64(trial))
96+
r := rand.New(rand.NewPCG(uint64(trial), uint64(trial)))
9797
for i := range keys {
98-
keys[i] = rand.Uint64()
98+
keys[i] = r.Uint64()
9999
}
100100
filter, _ = NewBinaryFuse[testType](keys)
101101
for _, v := range keys {
@@ -317,7 +317,7 @@ func TestBinaryFuseN_Issue35(t *testing.T) {
317317
for test := 0; test < 100; test++ {
318318
hashes := make([]uint64, 0)
319319
for i := 0; i < 40000; i++ {
320-
v := encode(int32(rand.Intn(10)), int32(rand.Intn(100000)))
320+
v := encode(rand.Int32N(10), rand.Int32N(100000))
321321
hashes = append(hashes, xxhash.Sum64(v))
322322
}
323323
inner, err := NewBinaryFuse[testType](hashes)

xorfilter_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package xorfilter
22

33
import (
44
"fmt"
5-
"math/rand"
5+
"math/rand/v2"
66
"testing"
77
"time"
88
"unsafe"
@@ -182,7 +182,7 @@ func BenchmarkXor8bigContains50000000(b *testing.B) {
182182
func TestFSDIssue35_basic(t *testing.T) {
183183
hashes := make([]uint64, 0)
184184
for i := 0; i < 2000; i++ {
185-
v := encode(int32(rand.Intn(10)), int32(rand.Intn(100000)))
185+
v := encode(rand.Int32N(10), rand.Int32N(100000))
186186
hashes = append(hashes, xxhash.Sum64(v))
187187
}
188188
inner, err := Populate(hashes)
@@ -202,7 +202,7 @@ func Test_Issue35_basic(t *testing.T) {
202202
for test := 0; test < 100; test++ {
203203
hashes := make([]uint64, 0)
204204
for i := 0; i < 40000; i++ {
205-
v := encode(int32(rand.Intn(10)), int32(rand.Intn(100000)))
205+
v := encode(rand.Int32N(10), rand.Int32N(100000))
206206
hashes = append(hashes, xxhash.Sum64(v))
207207
}
208208
inner, err := PopulateBinaryFuse8(hashes)

0 commit comments

Comments
 (0)