I've written a tip and I think it can help.

How to generate many random various numbers?[^]

briefly:

C#

//C# 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:

//C# Random random = new Random(); List<int> numbers = new List<int>(); for (int i = 0; i <= 1000; i++) { numbers.Add(i); } //Ok, For each using the method, there is a new and defferent random number: 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.