MCPcopy
hub / github.com/caddyserver/caddy / randString

Function randString

modules/caddyhttp/errors.go:90–104  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

88// confusing characters like I, l, 1, 0, O, etc. If sameCase
89// is true, then uppercase letters are excluded.
90func 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
106func trace() string {
107 if pc, file, line, ok := runtime.Caller(2); ok {

Callers 1

ErrorFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected