add jitter (#1298)

This commit is contained in:
Asim Aslam 2020-03-04 15:37:17 +00:00 committed by GitHub
parent 9386f36a13
commit 67c26c71b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

17
util/jitter/jitter.go Normal file
View File

@ -0,0 +1,17 @@
// Package jitter provides a random jitter
package jitter
import (
"math/rand"
"time"
)
var (
r = rand.New(rand.NewSource(time.Now().UnixNano()))
)
// Do returns a random time to jitter with max cap specified
func Do(d time.Duration) time.Duration {
v := r.Float64() * float64(d.Nanoseconds())
return time.Duration(v)
}