Explorar o código

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

This provides a better random distribution and is easier to read.
Tamir Duberstein %!s(int64=10) %!d(string=hai) anos
pai
achega
5250784b09
Modificáronse 1 ficheiros con 1 adicións e 1 borrados
  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