Skip to content

Commit

Permalink
修复bug (#164)
Browse files Browse the repository at this point in the history
* 优化生成随机字符串

* 修复在32位机器上MaximumCapacity超过int最大值

---------

Co-authored-by: zhuhebin <zhuhebin@fengtaisec.com>
Co-authored-by: Inhere <inhere@users.noreply.github.com>
  • Loading branch information
3 people committed Mar 24, 2024
1 parent 7c5136a commit b77a7f1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions strutil/random.go
Expand Up @@ -12,7 +12,7 @@ import (

// some consts string chars
const (
MaximumCapacity = 1 << 31
MaximumCapacity = math.MaxInt>>1 + 1
Numbers = "0123456789"
HexChars = "0123456789abcdef" // base16

Expand Down Expand Up @@ -76,7 +76,7 @@ func buildRandomString(letters string, length int) string {
cache, remain = rn.Int63(), letterIdMax
}
// 从可用字符的字符串中随机选择一个字符
if idx := int(cache & letterIdMask); idx < len(letters) {
if idx := int(cache & letterIdMask); idx < strLength {
bytes[i] = letters[idx]
i--
}
Expand Down

0 comments on commit b77a7f1

Please sign in to comment.