Generate Random Number in Min to Max Range

Use the Next(int min, int max) overload method to get a random integer that is within a specified range.

Random random = new Random();

for(int i = 0; i < 4; i++)
{
    Console.WriteLine(random.Next(10, 20)); // returns random integers >= 10 and < 19
}

Comments