Skip to content

Instantly share code, notes, and snippets.

@ramonsmits
Created December 16, 2019 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramonsmits/5fa165b27c5964eef56b6629a4c59fa0 to your computer and use it in GitHub Desktop.
Save ramonsmits/5fa165b27c5964eef56b6629a4c59fa0 to your computer and use it in GitHub Desktop.
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