1
1
package testutil
2
2
3
3
import (
4
- crand "crypto/rand"
5
4
"encoding/hex"
6
5
"math/rand"
7
6
"testing"
7
+ "time"
8
8
9
9
"github.com/stretchr/testify/require"
10
10
)
@@ -20,7 +20,7 @@ const (
20
20
defaultBytesFixedSize = 16
21
21
)
22
22
23
- func IntProvider (t * testing.T ) int { return rand .Int () }
23
+ func IntProvider (t * testing.T ) int { return r .Int () }
24
24
25
25
func IntRangedProvider (min , max int ) func (* testing.T ) int {
26
26
return func (t * testing.T ) int {
@@ -29,14 +29,22 @@ func IntRangedProvider(min, max int) func(*testing.T) int {
29
29
t .Fatalf ("invalid range [%d, %d)" , min , max )
30
30
}
31
31
32
- return min + rand .Intn (gap )
32
+ return min + r .Intn (gap )
33
33
}
34
34
}
35
35
36
+ var r = rand .New (rand .NewSource (time .Now ().UnixNano ()))
37
+
38
+ func getRand () * rand.Rand {
39
+ seed := time .Now ().UnixNano ()
40
+ r = rand .New (rand .NewSource (seed ))
41
+ return rand .New (rand .NewSource (seed ))
42
+ }
43
+
36
44
func BytesFixedProvider (size int ) func (* testing.T ) []byte {
37
45
return func (t * testing.T ) []byte {
38
46
b := make ([]byte , size )
39
- _ , err := crand .Read (b [:])
47
+ _ , err := r .Read (b [:])
40
48
require .NoError (t , err )
41
49
return b
42
50
}
@@ -45,7 +53,7 @@ func BytesFixedProvider(size int) func(*testing.T) []byte {
45
53
func BytesAtMostProvider (size int ) func (* testing.T ) []byte {
46
54
return func (t * testing.T ) []byte {
47
55
b := make ([]byte , rand .Intn (size ))
48
- _ , err := crand .Read (b [:])
56
+ _ , err := r .Read (b [:])
49
57
require .NoError (t , err )
50
58
return b
51
59
}
0 commit comments