using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Security.Cryptography;
namespace AgainstMordridV1.Classes
{
public class BaseRandom
{
public static int GetRandomNumber(int iMin, int irRandValRange, RNGCryptoServiceProvider Gen)
{
if (Gen == null)
Gen = new RNGCryptoServiceProvider();
if (irRandValRange == 0)
irRandValRange = 1;
byte[] randomNumber = new byte[4]; // 4 bytes per Int32
Gen.GetBytes(randomNumber);
return BitConverter.ToInt32(randomNumber, 0) % irRandValRange + 1;
}
public static int GetDiceRoll(int DNum)
{
return GetRandomNumber(1, DNum, null);
}
public static int GetDiceRoll(int DNum, RNGCryptoServiceProvider Gen)
{
if (Gen == null)
Gen = new RNGCryptoServiceProvider();
return GetRandomNumber(1, DNum, Gen);
}
public static int GetMultiDiceRollsTotal(int DNum, int Rolls)
{
RNGCryptoServiceProvider Gen = new RNGCryptoServiceProvider();
if (DNum * Rolls > Int32.MaxValue)
{
throw new Exception("Dice params too Big");
}
int iCount = 0;
for (int i = 0; i < Rolls; i++)
{
iCount += GetDiceRoll(DNum, Gen);
}
return iCount;
}
public static int GetD6Successes(int Rolls)
{
RNGCryptoServiceProvider Gen = new RNGCryptoServiceProvider();
if (6 * Rolls > Int32.MaxValue)
{
throw new Exception("Dice params too Big");
}
int iCount = 0;
int iTemp = 0;
for (int i = 0; i < Rolls; i++)
{
iTemp = GetDiceRoll(6, Gen);
if (iTemp > 3)
iCount++;
if (iTemp == 6)
i--;
}
return iCount;
}
}
}