Skip to content

Instantly share code, notes, and snippets.

@Pompeu
Created November 23, 2017 12:33
Show Gist options
  • Select an option

  • Save Pompeu/b0c713adbfb6eb5e9201ee22b5630afd to your computer and use it in GitHub Desktop.

Select an option

Save Pompeu/b0c713adbfb6eb5e9201ee22b5630afd to your computer and use it in GitHub Desktop.
C# Randon
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System;
using System.Threading;
namespace Rextester
{
public class Program
{
public static void Main(string[] args)
{
// var rnd = new Random();
// Enumerable.Range(1,49).OrderBy(x => rnd.Next()).Take(6).ToList().ForEach(Console.WriteLine);
Console.WriteLine(RandomProvider.GetThreadRandom().Next(100));
Console.WriteLine(RandomProvider.GetThreadRandom().Next(100));
Console.WriteLine(RandomProvider.GetThreadRandom().Next(100));
Console.WriteLine(RandomProvider.GetThreadRandom().Next(100));
}
}
public static class RandomProvider
{
private static int seed = Environment.TickCount;
private static ThreadLocal<Random> randomWrapper = new ThreadLocal<Random>
(() => new Random(Interlocked.Increment(ref seed)));
public static Random GetThreadRandom()
{
return randomWrapper.Value;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment