From 64cc2644f692d3ed2064f15cfd2b620f79e627c0 Mon Sep 17 00:00:00 2001 From: Matheus Lima Date: Wed, 25 Jan 2023 01:13:55 -0300 Subject: [PATCH] add pseudo random seed to the pseudo random Shuffle --- generic.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/generic.go b/generic.go index f3cd810..13f6d82 100644 --- a/generic.go +++ b/generic.go @@ -5,6 +5,7 @@ import ( "math/rand" "reflect" "sort" + "time" "github.com/thefuga/go-collections/errors" "github.com/thefuga/go-collections/internal" @@ -648,7 +649,10 @@ func RandomE[V any](slice []V) (V, error) { // Shuffle pseudo-randomizes the order of elements. func Shuffle[V any](slice []V) []V { - rand.Shuffle(len(slice), func(i, j int) { + seed := rand.NewSource(time.Now().UnixNano()) + r := rand.New(seed) + + r.Shuffle(len(slice), func(i, j int) { slice[i], slice[j] = slice[j], slice[i] }) return slice