Преглед на файлове

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

This provides a better random distribution and is easier to read.
Tamir Duberstein преди 9 години
родител
ревизия
5250784b09
променени са 1 файла, в които са добавени 1 реда и са изтрити 1 реда
  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