mirror of
https://github.com/oarkflow/mq.git
synced 2025-10-05 16:06:55 +08:00
12 lines
270 B
Go
12 lines
270 B
Go
package utils
|
|
|
|
import (
|
|
"math/rand"
|
|
"time"
|
|
)
|
|
|
|
func CalculateJitter(baseDelay time.Duration, percent float64) time.Duration {
|
|
jitter := time.Duration(rand.Float64()*percent*float64(baseDelay)) - time.Duration(percent*float64(baseDelay)/2)
|
|
return baseDelay + jitter
|
|
}
|