Skip to content

Commit

Permalink
test: use math/rand/v2
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Juneezee authored and lemire committed Jan 1, 2025
1 parent 20a6abb commit 51abaa4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions binaryfusefilter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package xorfilter

import (
"fmt"
"math/rand"
"math/rand/v2"
"testing"

"github.com/cespare/xxhash"
Expand Down Expand Up @@ -43,9 +43,9 @@ func TestBinaryFuseNBasic(t *testing.T) {
}
keys = keys[:cut]
for trial := 0; trial < 10; trial++ {
rand.Seed(int64(trial))
r := rand.New(rand.NewPCG(uint64(trial), uint64(trial)))
for i := range keys {
keys[i] = rand.Uint64()
keys[i] = r.Uint64()
}
filter, _ = NewBinaryFuse[testType](keys)
for _, v := range keys {
Expand Down Expand Up @@ -93,9 +93,9 @@ func TestBinaryFuseNSmall(t *testing.T) {
}
keys = keys[:cut]
for trial := 0; trial < 10; trial++ {
rand.Seed(int64(trial))
r := rand.New(rand.NewPCG(uint64(trial), uint64(trial)))
for i := range keys {
keys[i] = rand.Uint64()
keys[i] = r.Uint64()
}
filter, _ = NewBinaryFuse[testType](keys)
for _, v := range keys {
Expand Down Expand Up @@ -317,7 +317,7 @@ func TestBinaryFuseN_Issue35(t *testing.T) {
for test := 0; test < 100; test++ {
hashes := make([]uint64, 0)
for i := 0; i < 40000; i++ {
v := encode(int32(rand.Intn(10)), int32(rand.Intn(100000)))
v := encode(rand.Int32N(10), rand.Int32N(100000))
hashes = append(hashes, xxhash.Sum64(v))
}
inner, err := NewBinaryFuse[testType](hashes)
Expand Down
6 changes: 3 additions & 3 deletions xorfilter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package xorfilter

import (
"fmt"
"math/rand"
"math/rand/v2"
"testing"
"time"
"unsafe"
Expand Down Expand Up @@ -182,7 +182,7 @@ func BenchmarkXor8bigContains50000000(b *testing.B) {
func TestFSDIssue35_basic(t *testing.T) {
hashes := make([]uint64, 0)
for i := 0; i < 2000; i++ {
v := encode(int32(rand.Intn(10)), int32(rand.Intn(100000)))
v := encode(rand.Int32N(10), rand.Int32N(100000))
hashes = append(hashes, xxhash.Sum64(v))
}
inner, err := Populate(hashes)
Expand All @@ -202,7 +202,7 @@ func Test_Issue35_basic(t *testing.T) {
for test := 0; test < 100; test++ {
hashes := make([]uint64, 0)
for i := 0; i < 40000; i++ {
v := encode(int32(rand.Intn(10)), int32(rand.Intn(100000)))
v := encode(rand.Int32N(10), rand.Int32N(100000))
hashes = append(hashes, xxhash.Sum64(v))
}
inner, err := PopulateBinaryFuse8(hashes)
Expand Down

0 comments on commit 51abaa4

Please sign in to comment.