mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-04 12:52:28 +08:00
修复MAXIMUM_CAPACITY超过int最大值 (#196)
* refactor:refactor random function * fix:fix random function --------- Co-authored-by: zhuhebin <zhuhebin@fengtaisec.com>
This commit is contained in:
@@ -17,7 +17,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
MaximumCapacity = 1 << 31
|
||||
MaximumCapacity = math.MaxInt>>1 + 1
|
||||
Numeral = "0123456789"
|
||||
LowwerLetters = "abcdefghijklmnopqrstuvwxyz"
|
||||
UpperLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
@@ -157,7 +157,7 @@ func random(s string, length int) string {
|
||||
cache, remain = rn.Int63(), letterIdMax
|
||||
}
|
||||
// 从可用字符的字符串中随机选择一个字符
|
||||
if idx := int(cache & letterIdMask); idx < len(s) {
|
||||
if idx := int(cache & letterIdMask); idx < strLength {
|
||||
bytes[i] = s[idx]
|
||||
i--
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user