Skip to content

Instantly share code, notes, and snippets.

@hidori
Last active December 24, 2015 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hidori/c674416c9b8c05c6ee9f to your computer and use it in GitHub Desktop.
Save hidori/c674416c9b8c05c6ee9f to your computer and use it in GitHub Desktop.
C# Advent Calendar 2015-12-25 #3
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