Ver código fonte

raft: use rand.Intn instead of rand.Int and mod

This provides a better random distribution and is easier to read.
Tamir Duberstein 9 anos atrás
pai
commit
5250784b09
1 arquivos alterados com 1 adições e 1 exclusões
  1. 1 1
      raft/raft.go

+ 1 - 1
raft/raft.go

@@ -877,7 +877,7 @@ func (r *raft) pastElectionTimeout() bool {
 }
 
 func (r *raft) resetRandomizedElectionTimeout() {
-	r.randomizedElectionTimeout = r.electionTimeout + r.rand.Int()%r.electionTimeout
+	r.randomizedElectionTimeout = r.electionTimeout + r.rand.Intn(r.electionTimeout)
 }
 
 // checkQuorumActive returns true if the quorum is active from