From 146c5b0a597f4f2482815f3978a99c11b5528b4f Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Thu, 18 Feb 2016 15:17:42 -0800 Subject: [PATCH] Use `rand.Int31n()` to get power of two optimization In cases where i+1 is a power of two, skip one modulo operation. --- consul/structs/structs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/consul/structs/structs.go b/consul/structs/structs.go index 3e7ef5955e..d582560cd8 100644 --- a/consul/structs/structs.go +++ b/consul/structs/structs.go @@ -410,7 +410,7 @@ type CheckServiceNodes []CheckServiceNode // Shuffle does an in-place random shuffle using the Fisher-Yates algorithm. func (nodes CheckServiceNodes) Shuffle() { for i := len(nodes) - 1; i > 0; i-- { - j := rand.Int31() % int32(i+1) + j := rand.Int31n(int32(i + 1)) nodes[i], nodes[j] = nodes[j], nodes[i] } }