#region Usings
using System;
using System.Security.Cryptography;
#endregion
namespace Novetus.Core
{
#region CryptoRandom
public class CryptoRandom : RandomNumberGenerator
{
private static RandomNumberGenerator r;
public CryptoRandom()
{
r = Create();
}
///An array of bytes to contain random numbers.
public override void GetBytes(byte[] buffer)
{
r.GetBytes(buffer);
}
public override void GetNonZeroBytes(byte[] data)
{
r.GetNonZeroBytes(data);
}
public double NextDouble()
{
byte[] b = new byte[4];
r.GetBytes(b);
return (double)BitConverter.ToUInt32(b, 0) / UInt32.MaxValue;
}
///The inclusive lower bound of the random number returned.
///The exclusive upper bound of the random number returned. maxValue must be greater than or equal to minValue.
public int Next(int minValue, int maxValue)
{
return (int)Math.Round(NextDouble() * (maxValue - minValue - 1)) + minValue;
}
public int Next()
{
return Next(0, int.MaxValue);
}
///The inclusive upper bound of the random number returned. maxValue must be greater than or equal 0
public int Next(int maxValue)
{
return Next(0, maxValue);
}
}
#endregion
}