C# How to generate non repeating random numbers

List<int> numbers = new List<int>();
Random random = new Random();
while (numbers.Count != 10)
{
    int number = random.Next(1, 11);
    if (!numbers.Contains(number))
    {
        numbers.Add(number);
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *