0
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-23 22:27:38 -05:00

context: Fix computation for random length of random string

This commit is contained in:
Matthew Holt 2017-04-15 16:48:44 -06:00
parent edf9cd34cc
commit 5a1243ff42
No known key found for this signature in database
GPG key ID: 2A349DD577D586A5

View file

@ -367,12 +367,12 @@ func (c Context) RandomString(minLen, maxLen int) string {
letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits
) )
if minLen < 0 || maxLen < 0 || maxLen <= minLen { if minLen < 0 || maxLen < 0 || maxLen < minLen {
return "" return ""
} }
src := rand.NewSource(time.Now().UnixNano()) src := rand.NewSource(time.Now().UnixNano())
n := rand.Intn(maxLen-minLen) + minLen // choose actual length n := rand.Intn(maxLen-minLen+1) + minLen // choose actual length
b := make([]byte, n) b := make([]byte, n)
for i, cache, remain := n-1, src.Int63(), letterIdxMax; i >= 0; { for i, cache, remain := n-1, src.Int63(), letterIdxMax; i >= 0; {
if remain == 0 { if remain == 0 {