Export RandDurationN

This commit is contained in:
Ian Gulliver
2023-06-11 09:57:48 -07:00
parent d8049f4895
commit 906e3df38a
2 changed files with 12 additions and 7 deletions

View File

@@ -4,7 +4,6 @@ import (
"crypto/hmac"
"encoding/json"
"log"
"math/rand"
"time"
"github.com/dchest/uniuri"
@@ -79,13 +78,13 @@ func (v *Voter) loop() {
}
func (v *Voter) poll() bool {
t := time.NewTimer(randDurationN(v.period))
t := time.NewTimer(RandDurationN(v.period))
defer t.Stop()
t2 := &time.Timer{}
if v.vote.NumPollsSinceChange <= 10 {
t2 = time.NewTimer(randDurationN(maxFastVotePeriod))
t2 = time.NewTimer(RandDurationN(maxFastVotePeriod))
defer t2.Stop()
}
@@ -168,7 +167,3 @@ func (v *Voter) sendVote() {
func (v *Voter) log(format string, args ...any) {
log.Printf("[voter] "+format, args...)
}
func randDurationN(n time.Duration) time.Duration {
return time.Duration(rand.Int63n(int64(n))) //nolint:gosec
}