I want to generate a list of N different random numbers.
I'm doing this in a following way:
public static List<int> GetRandomNumbers(int count)
{
List<int> randomNumbers = new List<int>();
for (int i=0; i<count; i++)
{
int number;
do number = random.Next();
while (randomNumbers.Contains(number));
randomNumbers.Add(number);
}
return randomNumbers;
}
But I feel there is a better way. Especially this This do...while loop especially makes this ugly. Any suggestions on how to improve this?