mirror of
https://github.com/status-im/consul.git
synced 2025-01-26 13:40:20 +00:00
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
77ad084229
commit
146c5b0a59
@ -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…
x
Reference in New Issue
Block a user