日期:2014-05-17 浏览次数:20435 次
public static class RealRandom
{
/// <summary>
/// 生成小于输入值绝对值的随机数
/// </summary>
/// <param name="NumSides"></param>
/// <returns></returns>
public static int Next(this int numSeeds)
{
numSeeds = Math.Abs(numSeeds);
if (numSeeds <= 1)
{
return 0;
}
int length = 4;
if (numSeeds <= byte.MaxValue)
{
length = 1;
}
else if (numSeeds <= short.MaxValue)
{
length = 2;
}
return Next(numSeeds, length);
}
private static int Next(int numSeeds, int length)
{
// Create a byte array to hold the random value.
byte[] buffer = new byte[length];
// Create a new instance of the RNGCryptoServiceProvider.
System.Security.Cryptography.RNGCryptoServiceProvider Gen = new Sy