From 8c6c1fa8c3423ac939df022103b800cf26c07fef Mon Sep 17 00:00:00 2001 From: CareyWong Date: Sun, 29 Mar 2020 20:11:00 +0800 Subject: [PATCH] Fix: first time generate same key --- main.go | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/main.go b/main.go index 6eb9315..2cda9de 100644 --- a/main.go +++ b/main.go @@ -30,11 +30,6 @@ type redisPoolConf struct { } const letterBytes = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" -const ( - letterIdxBits = 6 // 6 bits to represent a letter index - letterIdxMask = 1<= 0; { - if remain == 0 { - cache, remain = rand.Int63(), letterIdxMax - } - if idx := int(cache & letterIdxMask); idx < len(letterBytes) { - b[i] = letterBytes[idx] - i-- - } - cache >>= letterIdxBits - remain-- + currentTime := time.Now().Unix() + for i := range b { + b[i] = letterBytes[(currentTime + rand.Int63()) % int64(len(letterBytes))] } - return string(b) }