1
0
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:
pigwantacat
2024-03-01 15:52:49 +08:00
committed by GitHub
parent e9380a3d9f
commit 235d2f2486

View File

@@ -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--
}