Created
November 23, 2017 12:33
-
-
Save Pompeu/b0c713adbfb6eb5e9201ee22b5630afd to your computer and use it in GitHub Desktop.
C# Randon
This file contains hidden or 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
| 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