using System; using System.Threading; namespace JwKdsV.Core.LoadBalance { /// /// Create random numbers with Thread-specific seeds. /// /// Borrowed form Jon Skeet's brilliant C# in Depth: http://csharpindepth.com/Articles/Chapter12/Random.aspx /// public static class ThreadLocalRandom { private static int _seed = Environment.TickCount; private static ThreadLocal _randomWrapper = new ThreadLocal(() => new Random(Interlocked.Increment(ref _seed))); /// /// The current random number seed available to this thread /// public static Random Current { get { return _randomWrapper.Value; } } } }