Created
December 16, 2019 20:06
-
-
Save ramonsmits/5fa165b27c5964eef56b6629a4c59fa0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class Jitter | |
{ | |
static readonly Random Random = new Random(); | |
public static TimeSpan Next(int count, TimeSpan first) | |
{ | |
double jitter; | |
lock (Random) jitter = Random.NextDouble(); // Needed to make random threadsafe | |
return TimeSpan.FromTicks((long) (first.Ticks * Math.Pow(2, count + jitter))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment