Last active
December 24, 2015 07:37
-
-
Save hidori/c674416c9b8c05c6ee9f to your computer and use it in GitHub Desktop.
C# Advent Calendar 2015-12-25 #3
This file contains 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.Security.Cryptography; | |
namespace ConsoleApplication3 | |
{ | |
static class BetterRandom | |
{ | |
static readonly Random Random; | |
static BetterRandom() | |
{ | |
using (var provider = new RNGCryptoServiceProvider()) | |
{ | |
var bytes = new byte[8]; | |
provider.GetBytes(bytes); | |
var seed = BitConverter.ToInt32(bytes, 0); | |
Random = new Random(seed); | |
} | |
} | |
public static Random GetRandom() | |
{ | |
return Random; | |
} | |
} | |
static class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var random = BetterRandom.GetRandom(); | |
for (var i = 0; i < 100; i++) | |
{ | |
var value = random.Next(); | |
Console.WriteLine(value); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment