Hi,
I've written a tip and I think it can help.
How to generate many random various numbers?[
^]
briefly:
public static int RandomNumber(ref List<int> numbers, Random random)
{
int count = numbers.Count;
int randomIndex = random.Next(0, count);
int returnedNumber = numbers[randomIndex];
numbers.RemoveAt(randomIndex);
return returnedNumber;
}
It's requisite for using the method, to have a random variable and a list of numbers, for example:
Random random = new Random();
List<int> numbers = new List<int>();
for (int i = 0; i <= 1000; i++)
{
numbers.Add(i);
}
Console.WriteLine(RandomNumber(ref numbers, random));
Console.WriteLine(RandomNumber(ref numbers, random));
Console.WriteLine(RandomNumber(ref numbers, random));
Console.WriteLine(RandomNumber(ref numbers, random));
Console.WriteLine(RandomNumber(ref numbers, random));
Console.ReadKey();
And I think you'll see a good performance.