Skip to content

Instantly share code, notes, and snippets.

@hidori
Last active December 24, 2015 07:36
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/17b5558afd17be4cfd0c to your computer and use it in GitHub Desktop.
Save hidori/17b5558afd17be4cfd0c to your computer and use it in GitHub Desktop.
C# Advent Calendar 2015-12-25 #2
using System;
using System.Security.Cryptography;
namespace ConsoleApplication2
{
class BetterRandom
{
public int Next()
{
using (var provider = new RNGCryptoServiceProvider())
{
var bytes = new byte[4];
provider.GetBytes(bytes);
var value = BitConverter.ToInt32(bytes, 0) & 0x7fffff;
return value;
}
}
}
static class Program
{
static void Main(string[] args)
{
var random = new BetterRandom();
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