I have a program which works with arrays and at some point I have to check if a lsit of values are inside an array, the function that does this takes about 70% of the program CP
I found a method, thanks to @sous2817 comment, that works perfectly for me.
public static int[] GetRandomNumbers(int count, Random RNG)
{
HashSet randomNumbers = new HashSet();
for (int i = 0; i < count; i++)
while (!randomNumbers.Add(RNG.Next(count))) ;
return randomNumbers.ToArray();
}
This works ~10 times faster then what I was doing and works nicely with the rest of my program.I needed the code to be "linear" so other solutions mess my program. Anyway, thanks to everyone that helped :)