Skip to content

Commit d98774e

Browse files
seankhliaogopherbot
authored andcommitted
cmd/signature-fuzzer/internal/fuzz-generator: update to math/rand/v2
Fixes golang/go#71613 Change-Id: Id69044282568b3564aee82dfe4c1b98c41d16d0f Reviewed-on: https://go-review.googlesource.com/c/tools/+/647896 Reviewed-by: Than McIntosh <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]> Reviewed-by: Cherry Mui <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 2593262 commit d98774e

File tree

1 file changed

+7
-7
lines changed
  • cmd/signature-fuzzer/internal/fuzz-generator

1 file changed

+7
-7
lines changed

cmd/signature-fuzzer/internal/fuzz-generator/wraprand.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package generator
66

77
import (
88
"fmt"
9-
"math/rand"
9+
"math/rand/v2"
1010
"os"
1111
"runtime"
1212
"strings"
@@ -20,8 +20,7 @@ const (
2020
)
2121

2222
func NewWrapRand(seed int64, ctl int) *wraprand {
23-
rand.Seed(seed)
24-
return &wraprand{seed: seed, ctl: ctl}
23+
return &wraprand{seed: seed, ctl: ctl, rand: rand.New(rand.NewPCG(0, uint64(seed)))}
2524
}
2625

2726
type wraprand struct {
@@ -32,6 +31,7 @@ type wraprand struct {
3231
tag string
3332
calls []string
3433
ctl int
34+
rand *rand.Rand
3535
}
3636

3737
func (w *wraprand) captureCall(tag string, val string) {
@@ -59,7 +59,7 @@ func (w *wraprand) captureCall(tag string, val string) {
5959

6060
func (w *wraprand) Intn(n int64) int64 {
6161
w.intncalls++
62-
rv := rand.Int63n(n)
62+
rv := w.rand.Int64N(n)
6363
if w.ctl&RandCtlCapture != 0 {
6464
w.captureCall("Intn", fmt.Sprintf("%d", rv))
6565
}
@@ -68,7 +68,7 @@ func (w *wraprand) Intn(n int64) int64 {
6868

6969
func (w *wraprand) Float32() float32 {
7070
w.f32calls++
71-
rv := rand.Float32()
71+
rv := w.rand.Float32()
7272
if w.ctl&RandCtlCapture != 0 {
7373
w.captureCall("Float32", fmt.Sprintf("%f", rv))
7474
}
@@ -77,15 +77,15 @@ func (w *wraprand) Float32() float32 {
7777

7878
func (w *wraprand) NormFloat64() float64 {
7979
w.f64calls++
80-
rv := rand.NormFloat64()
80+
rv := w.rand.NormFloat64()
8181
if w.ctl&RandCtlCapture != 0 {
8282
w.captureCall("NormFloat64", fmt.Sprintf("%f", rv))
8383
}
8484
return rv
8585
}
8686

8787
func (w *wraprand) emitCalls(fn string) {
88-
outf, err := os.OpenFile(fn, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
88+
outf, err := os.OpenFile(fn, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o666)
8989
if err != nil {
9090
panic(err)
9191
}

0 commit comments

Comments
 (0)