randString returns a string of n random characters. It is not even remotely secure OR a proper distribution. But it's good enough for some things. It excludes certain confusing characters like I, l, 1, 0, O, etc. If sameCase is true, then uppercase letters are excluded.
(n int, sameCase bool)
| 88 | // confusing characters like I, l, 1, 0, O, etc. If sameCase |
| 89 | // is true, then uppercase letters are excluded. |
| 90 | func randString(n int, sameCase bool) string { |
| 91 | if n <= 0 { |
| 92 | return "" |
| 93 | } |
| 94 | dict := []byte("abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRTUVWXY23456789") |
| 95 | if sameCase { |
| 96 | dict = []byte("abcdefghijkmnpqrstuvwxyz0123456789") |
| 97 | } |
| 98 | b := make([]byte, n) |
| 99 | for i := range b { |
| 100 | //nolint:gosec |
| 101 | b[i] = dict[weakrand.IntN(len(dict))] |
| 102 | } |
| 103 | return string(b) |
| 104 | } |
| 105 | |
| 106 | func trace() string { |
| 107 | if pc, file, line, ok := runtime.Caller(2); ok { |