@@ -6,7 +6,7 @@ package generator
6
6
7
7
import (
8
8
"fmt"
9
- "math/rand"
9
+ "math/rand/v2 "
10
10
"os"
11
11
"runtime"
12
12
"strings"
@@ -20,8 +20,7 @@ const (
20
20
)
21
21
22
22
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 )))}
25
24
}
26
25
27
26
type wraprand struct {
@@ -32,6 +31,7 @@ type wraprand struct {
32
31
tag string
33
32
calls []string
34
33
ctl int
34
+ rand * rand.Rand
35
35
}
36
36
37
37
func (w * wraprand ) captureCall (tag string , val string ) {
@@ -59,7 +59,7 @@ func (w *wraprand) captureCall(tag string, val string) {
59
59
60
60
func (w * wraprand ) Intn (n int64 ) int64 {
61
61
w .intncalls ++
62
- rv := rand .Int63n (n )
62
+ rv := w . rand .Int64N (n )
63
63
if w .ctl & RandCtlCapture != 0 {
64
64
w .captureCall ("Intn" , fmt .Sprintf ("%d" , rv ))
65
65
}
@@ -68,7 +68,7 @@ func (w *wraprand) Intn(n int64) int64 {
68
68
69
69
func (w * wraprand ) Float32 () float32 {
70
70
w .f32calls ++
71
- rv := rand .Float32 ()
71
+ rv := w . rand .Float32 ()
72
72
if w .ctl & RandCtlCapture != 0 {
73
73
w .captureCall ("Float32" , fmt .Sprintf ("%f" , rv ))
74
74
}
@@ -77,15 +77,15 @@ func (w *wraprand) Float32() float32 {
77
77
78
78
func (w * wraprand ) NormFloat64 () float64 {
79
79
w .f64calls ++
80
- rv := rand .NormFloat64 ()
80
+ rv := w . rand .NormFloat64 ()
81
81
if w .ctl & RandCtlCapture != 0 {
82
82
w .captureCall ("NormFloat64" , fmt .Sprintf ("%f" , rv ))
83
83
}
84
84
return rv
85
85
}
86
86
87
87
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 )
89
89
if err != nil {
90
90
panic (err )
91
91
}
0 commit comments