From b77a7f13e7eae6c9ad726c803d96e5e490d95903 Mon Sep 17 00:00:00 2001 From: pigwantacat <79680042+pigwantacat@users.noreply.github.com> Date: Sun, 24 Mar 2024 13:49:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug=20(#164)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 优化生成随机字符串 * 修复在32位机器上MaximumCapacity超过int最大值 --------- Co-authored-by: zhuhebin Co-authored-by: Inhere --- strutil/random.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/strutil/random.go b/strutil/random.go index 68914ea76..130dddeb6 100644 --- a/strutil/random.go +++ b/strutil/random.go @@ -12,7 +12,7 @@ import ( // some consts string chars const ( - MaximumCapacity = 1 << 31 + MaximumCapacity = math.MaxInt>>1 + 1 Numbers = "0123456789" HexChars = "0123456789abcdef" // base16 @@ -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-- }