public static class RandomNumber
{
private static RNGCryptoServiceProvider rngProvider = new RNGCryptoServiceProvider();
private static byte[] bytes = new byte[4];
public static int Next(int max)
{
if (max <= 0)
throw new ArgumentOutOfRangeException("max");
rngProvider.GetBytes(bytes);
int value = BitConverter.ToInt32(bytes, 0) % max;
if (value < 0)
value = -value;
return value;
}
}