From 5250784b091b0f9912988625521a020d956abc7e Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 5 Apr 2016 14:21:43 -0400 Subject: [PATCH] raft: use rand.Intn instead of rand.Int and mod This provides a better random distribution and is easier to read. --- raft/raft.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/raft/raft.go b/raft/raft.go index b17b292a1..4bb399c39 100644 --- a/raft/raft.go +++ b/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