Skip to content

Instantly share code, notes, and snippets.

@jshinevar

jshinevar/StaticRandom.cs

Last active May 28, 2017
Embed
What would you like to do?
//https://stackoverflow.com/questions/767999/random-number-generator-only-generating-one-random-number
public static class StaticRandom
{
private static int seed;
private static ThreadLocal<Random> threadLocal = new ThreadLocal<Random>
(() => new Random(Interlocked.Increment(ref seed)));
static StaticRandom()
{
seed = Environment.TickCount;
}
public static Random Instance { get { return threadLocal.Value; } }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment