用RNGCryptoServiceProvider获取随机数
public string GetRan(int NumSides)
{
byte[] randomNumber = new byte[NumSides];
Gen.GetBytes(randomNumber);
int rand = Convert.ToInt32(randomNumber[0]);
StringBuilder sb = new StringBuilder();
foreach (byte by in randomNumber)
{
sb.Append(Convert.ToInt32(by) % NumSides + 1);
}
return sb.ToString();
}
{
byte[] randomNumber = new byte[NumSides];
Gen.GetBytes(randomNumber);
int rand = Convert.ToInt32(randomNumber[0]);
StringBuilder sb = new StringBuilder();
foreach (byte by in randomNumber)
{
sb.Append(Convert.ToInt32(by) % NumSides + 1);
}
return sb.ToString();
}