From a769257017fe31256674bf497e54be9fefc92441 Mon Sep 17 00:00:00 2001 From: dudaodong Date: Mon, 11 Nov 2024 19:45:31 +0800 Subject: [PATCH] fix: update random seed when call random function --- random/random.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/random/random.go b/random/random.go index 1705324..1aa5db7 100644 --- a/random/random.go +++ b/random/random.go @@ -273,6 +273,9 @@ func nearestPowerOfTwo(cap int) int { // random generate a random string based on given string range. func random(s string, length int) string { + // 确保随机数生成器的种子是动态的 + rand.Seed(time.Now().UnixNano()) + // 仿照strings.Builder // 创建一个长度为 length 的字节切片 bytes := make([]byte, length)