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:
parent
edf9cd34cc
commit
5a1243ff42
1 changed files with 2 additions and 2 deletions
|
@ -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 {
|
||||||
|
|
Loading…
Reference in a new issue