/
githubmirror
/
client
Обзор
Документация
Войти
/
githubmirror
/
client
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
go/libkb/random_jitter.go
21 строка
427 B
Joshua Blum
Use RandomJitter to delay background operations (#22936)
09 мар 2020, 20:31
Не верифицирован
09 мар 2020, 20:31
854985a
Код
Авторство
О чём код?
package libkb import ( cryptorand "crypto/rand" "math/big" "time" ) // RandomJitter takes a duration of d, and output a duration uniformly // and randomly distributed in [.5d, 1.5d]. func RandomJitter(d time.Duration) time.Duration { r := int64(100000) nBig, err := cryptorand.Int(cryptorand.Reader, big.NewInt(r)) if err != nil { return d } x := int64(d) n := nBig.Int64() return time.Duration(3*x/2 - x*n/r) }