From 80958801346f4068cbfe0edfd527034b0fc0da53 Mon Sep 17 00:00:00 2001 From: Dhi Aurrahman Date: Thu, 30 Nov 2023 23:21:45 +0700 Subject: [PATCH] Make sure each call to NewRand is initialized with a unique seed Fixes: #1352. Signed-off-by: Dhi Aurrahman --- internal/util/rand/random.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/util/rand/random.go b/internal/util/rand/random.go index 8d8134ef92..4c6c696c66 100644 --- a/internal/util/rand/random.go +++ b/internal/util/rand/random.go @@ -33,11 +33,16 @@ import ( "net" "os" "path/filepath" + "sync/atomic" ) +// seedGuard makes sure each call to NewRand is initialized with a unique seed. +var seedGuard atomic.Int64 + // NewRand returns a new instance of rand.Rand with a fixed source. func NewRand(seed int64) *rand.Rand { - return rand.New(rand.NewSource(seed)) + seedGuard.Add(1) + return rand.New(rand.NewSource(seed + seedGuard.Load())) } // RandomInt returns a random integer between min and max.