Skip to content

Commit 1b8717f

Browse files
authored
Switch to math/rand/v2 (#149)
The new APIs allow for some cleanup in the common usages we have around uint64. The only downside is that this is go1.22+, but we've already committed to that in the go.mod file.
1 parent 524aacd commit 1b8717f

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

compact/range_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"errors"
2121
"fmt"
2222
"math/bits"
23-
"math/rand"
23+
"math/rand/v2"
2424
"reflect"
2525
"testing"
2626

@@ -272,9 +272,9 @@ func TestMergeInBatches(t *testing.T) {
272272

273273
// Build many trees of random size by randomly merging their sub-ranges.
274274
func TestMergeRandomly(t *testing.T) {
275-
for seed := int64(1); seed < 100; seed++ {
275+
for seed := uint64(1); seed < 100; seed++ {
276276
t.Run(fmt.Sprintf("seed:%d", seed), func(t *testing.T) {
277-
rnd := rand.New(rand.NewSource(seed))
277+
rnd := rand.New(rand.NewPCG(0, seed))
278278
numNodes := rand.Uint64() % 500
279279
t.Logf("Tree size: %d", numNodes)
280280

@@ -287,7 +287,7 @@ func TestMergeRandomly(t *testing.T) {
287287
t.Fatalf("Append(%d): %v", begin, err)
288288
}
289289
} else if begin < end {
290-
mid := begin + uint64(rnd.Int63n(int64(end-begin)))
290+
mid := begin + rnd.Uint64N(end-begin)
291291
if err := rng.AppendRange(mergeAll(begin, mid), visit); err != nil {
292292
t.Fatalf("AppendRange(%d,%d): %v", begin, mid, err)
293293
}

testonly/tree_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package testonly
1717
import (
1818
"bytes"
1919
"fmt"
20-
"math/rand"
20+
"math/rand/v2"
2121
"strconv"
2222
"testing"
2323

@@ -140,11 +140,11 @@ func TestTreeConsistencyProof(t *testing.T) {
140140
func TestTreeConsistencyProofFuzz(t *testing.T) {
141141
entries := genEntries(256)
142142

143-
for treeSize := int64(1); treeSize <= 256; treeSize++ {
143+
for treeSize := uint64(1); treeSize <= 256; treeSize++ {
144144
mt := newTree(entries[:treeSize])
145145
for i := 0; i < 8; i++ {
146-
size2 := uint64(rand.Int63n(treeSize + 1))
147-
size1 := uint64(rand.Int63n(int64(size2) + 1))
146+
size2 := rand.Uint64N(treeSize + 1)
147+
size1 := rand.Uint64N(size2 + 1)
148148

149149
got, err := mt.ConsistencyProof(size1, size2)
150150
if err != nil {

0 commit comments

Comments
 (0)