namespace FeedbackGeneratorQQ.Utils
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
public static class RandomGenerator
{
private static readonly RNGCryptoServiceProvider CryptRng = new RNGCryptoServiceProvider();
const long _max = (1 + (long)uint.MaxValue);
///
/// Gets random integer number from the given interval
///
/// Min value (including)
/// Max value (excluding)
/// Returns random integer number
public static int GetRandomNumber(int minValue, int maxValue)
{
if (minValue == maxValue)
{
return minValue;
}
byte[] bytes = new byte[4];
long diff = maxValue - minValue;
while (true)
{
CryptRng.GetBytes(bytes);
uint rand = BitConverter.ToUInt32(bytes, 0);
long remainder = _max % diff;
if (rand < _max - remainder)
{
return (int)(minValue + (rand % diff));
}
}
}
public static IList Shuffle(this IList list)
{
return list.OrderBy(a => GetRandomNumber(0, list.Count * 3)).ToList();
}
}
}