github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/swarmkit/manager/dispatcher/period.go (about) 1 package dispatcher 2 3 import ( 4 "math/rand" 5 "time" 6 ) 7 8 type periodChooser struct { 9 period time.Duration 10 epsilon time.Duration 11 rand *rand.Rand 12 } 13 14 func newPeriodChooser(period, eps time.Duration) *periodChooser { 15 return &periodChooser{ 16 period: period, 17 epsilon: eps, 18 rand: rand.New(rand.NewSource(time.Now().UnixNano())), 19 } 20 } 21 22 func (pc *periodChooser) Choose() time.Duration { 23 var adj int64 24 if pc.epsilon > 0 { 25 adj = rand.Int63n(int64(2*pc.epsilon)) - int64(pc.epsilon) 26 } 27 return pc.period + time.Duration(adj) 28 }