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:
parent
0f23210628
commit
d1ef4ec7e2
|
@ -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]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue