You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Zero/ZeroLevel/Services/Utils/RRandom.cs

25 lines
658 B

5 years ago
using System;
using System.Security.Cryptography;
namespace ZeroLevel.Services.Utils
{
public static class RRandom
{
public static int RandomInteger(int min, int max)
{
uint scale = uint.MaxValue;
while (scale == uint.MaxValue)
{
byte[] four_bytes = RandomNumberGenerator.GetBytes(4);
5 years ago
scale = BitConverter.ToUInt32(four_bytes, 0);
}
return (int)(min + (max - min) * (scale / (double)uint.MaxValue));
}
public static bool OverLimit(int limit)
{
return RandomInteger(0, 1000) > limit;
}
}
}

Powered by TurnKey Linux.