Use `rand.Int31n()` to get power of two optimization

In cases where i+1 is a power of two, skip one modulo operation.
This commit is contained in:
Sean Chittenden 2016-02-18 15:17:42 -08:00
parent 77ad084229
commit 146c5b0a59
1 changed files with 1 additions and 1 deletions

View File

@ -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]
}
}