Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
feed.jitter
func jitterSleep(sleep int, beaconType string) {
rand.Seed(time.Now().UnixNano())
min := int(float64(sleep) * .90)
max := int(float64(sleep) * 1.10)
randomSleep := rand.Intn(max - min + 1) + min
log.Printf("[%s] Next beacon going out in %d seconds", beaconType, randomSleep)
time.Sleep(time.Duration(randomSleep) * time.Second)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment