History

test makefiles: add --seed flag and make data generated repeatable #5214

Nick Craig-Wood committed 5 years ago

Commit 60dcafe1 parent 813bf022 files · +26 −10Browse files

Showing the changes to lib/random (1 of 2 files). Show all

Unified · Split

lib/random/random.go+11−3
@@ -10,10 +10,11 @@ import ( · 9 unmodified lines
1010 "github.com/pkg/errors"
1111 )
1212
13−// String create a random string for test purposes.
13+// StringFn create a random string for test purposes using the random
14+// number generator function passed in.
1415 //
1516 // Do not use these for passwords.
16−func String(n int) string {
17+func StringFn(n int, randIntn func(n int) int) string {
1718 const (
1819 vowel = "aeiou"
1920 consonant = "bcdfghjklmnpqrstvwxyz"
@@ -25,11 +26,18 @@ func String(n int) string { · 5 unmodified lines
2526 for i := range out {
2627 source := pattern[p]
2728 p = (p + 1) % len(pattern)
28− out[i] = source[mathrand.Intn(len(source))]
29+ out[i] = source[randIntn(len(source))]
2930 }
3031 return string(out)
3132 }
3233
34+// String create a random string for test purposes.
35+//
36+// Do not use these for passwords.
37+func String(n int) string {
38+ return StringFn(n, mathrand.Intn)
39+}
40+
3341 // Password creates a crypto strong password which is just about
3442 // memorable. The password is composed of printable ASCII characters
3543 // from the base64 alphabet.