Last active
December 24, 2015 07:36
-
-
Save hidori/17b5558afd17be4cfd0c to your computer and use it in GitHub Desktop.
C# Advent Calendar 2015-12-25 #2
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 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