From 235d2f248608446e6afbb3c95ffb0a1e059d7102 Mon Sep 17 00:00:00 2001 From: pigwantacat <79680042+pigwantacat@users.noreply.github.com> Date: Fri, 1 Mar 2024 15:52:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DMAXIMUM=5FCAPACITY=E8=B6=85?= =?UTF-8?q?=E8=BF=87int=E6=9C=80=E5=A4=A7=E5=80=BC=20(#196)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor:refactor random function * fix:fix random function --------- Co-authored-by: zhuhebin --- random/random.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/random/random.go b/random/random.go index 6e0c8cf..230feb6 100644 --- a/random/random.go +++ b/random/random.go @@ -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-- }