2020-03-04 18:37:17 +03:00
|
|
|
// Package jitter provides a random jitter
|
|
|
|
package jitter
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2021-02-17 22:58:55 +03:00
|
|
|
"github.com/unistack-org/micro/v3/util/rand"
|
2020-03-04 18:37:17 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// Do returns a random time to jitter with max cap specified
|
|
|
|
func Do(d time.Duration) time.Duration {
|
2021-02-17 22:58:55 +03:00
|
|
|
var rng rand.Rand
|
|
|
|
v := rng.Float64() * float64(d.Nanoseconds())
|
2020-03-04 18:37:17 +03:00
|
|
|
return time.Duration(v)
|
|
|
|
}
|