time.go 404 B

1234567891011121314151617
  1. package raft
  2. import (
  3. "math/rand"
  4. "time"
  5. )
  6. // Waits for a random time between two durations and sends the current time on
  7. // the returned channel.
  8. func afterBetween(min time.Duration, max time.Duration) <-chan time.Time {
  9. rand := rand.New(rand.NewSource(time.Now().UnixNano()))
  10. d, delta := min, (max - min)
  11. if delta > 0 {
  12. d += time.Duration(rand.Int63n(int64(delta)))
  13. }
  14. return time.After(d)
  15. }