util/rand: replace all non crypto rand stuff with own rand package

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2021-02-17 22:58:55 +03:00
parent 67748a2132
commit 5596345382
6 changed files with 99 additions and 23 deletions

View File

@@ -2,16 +2,14 @@
package jitter
import (
"math/rand"
"time"
)
var (
r = rand.New(rand.NewSource(time.Now().UnixNano()))
"github.com/unistack-org/micro/v3/util/rand"
)
// Do returns a random time to jitter with max cap specified
func Do(d time.Duration) time.Duration {
v := r.Float64() * float64(d.Nanoseconds())
var rng rand.Rand
v := rng.Float64() * float64(d.Nanoseconds())
return time.Duration(v)
}