From a260e372d2bb5ce6df14acaf09d4b25021e21ff1 Mon Sep 17 00:00:00 2001 From: Tevin Zhang Date: Wed, 2 Nov 2016 15:49:58 +0800 Subject: [PATCH] Fix randomness of servers shuffling --- zk/util.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/zk/util.go b/zk/util.go index 769bbe87..12ef93c4 100644 --- a/zk/util.go +++ b/zk/util.go @@ -5,6 +5,7 @@ import ( "encoding/base64" "fmt" "math/rand" + "time" "strconv" "strings" ) @@ -47,8 +48,9 @@ func FormatServers(servers []string) []string { // stringShuffle performs a Fisher-Yates shuffle on a slice of strings func stringShuffle(s []string) { + r := rand.New(rand.NewSource(time.Now().UnixNano())) for i := len(s) - 1; i > 0; i-- { - j := rand.Intn(i + 1) + j := r.Intn(i + 1) s[i], s[j] = s[j], s[i] } }