Showing the changes to lib/random (1 of 2 files). Show all
Unified · Split
| @@ -10,10 +10,11 @@ import ( · 9 unmodified lines | |||
| 10 | "github.com/pkg/errors" | 10 | "github.com/pkg/errors" |
| 11 | ) | 11 | ) |
| 12 | 12 | ||
| 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. | ||
| 14 | // | 15 | // |
| 15 | // Do not use these for passwords. | 16 | // Do not use these for passwords. |
| 16 | func String(n int) string { | 17 | func StringFn(n int, randIntn func(n int) int) string { |
| 17 | const ( | 18 | const ( |
| 18 | vowel = "aeiou" | 19 | vowel = "aeiou" |
| 19 | consonant = "bcdfghjklmnpqrstvwxyz" | 20 | consonant = "bcdfghjklmnpqrstvwxyz" |
| @@ -25,11 +26,18 @@ func String(n int) string { · 5 unmodified lines | |||
| 25 | for i := range out { | 26 | for i := range out { |
| 26 | source := pattern[p] | 27 | source := pattern[p] |
| 27 | p = (p + 1) % len(pattern) | 28 | p = (p + 1) % len(pattern) |
| 28 | out[i] = source[mathrand.Intn(len(source))] | 29 | out[i] = source[randIntn(len(source))] |
| 29 | } | 30 | } |
| 30 | return string(out) | 31 | return string(out) |
| 31 | } | 32 | } |
| 32 | 33 | ||
| 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 | |||
| 33 | // Password creates a crypto strong password which is just about | 41 | // Password creates a crypto strong password which is just about |
| 34 | // memorable. The password is composed of printable ASCII characters | 42 | // memorable. The password is composed of printable ASCII characters |
| 35 | // from the base64 alphabet. | 43 | // from the base64 alphabet. |