1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-24 10:07:04 +02:00
go-micro/util/jitter/jitter.go

18 lines
329 B
Go
Raw Normal View History

2020-03-04 17:37:17 +02:00
// Package jitter provides a random jitter
package jitter
import (
"math/rand"
"time"
)
var (
r = rand.New(rand.NewSource(time.Now().UnixNano()))
)
2022-09-30 16:27:07 +02:00
// Do returns a random time to jitter with max cap specified.
2020-03-04 17:37:17 +02:00
func Do(d time.Duration) time.Duration {
v := r.Float64() * float64(d.Nanoseconds())
return time.Duration(v)
}