To generate random numbers, use Random class.
Create an object −
Random r = new Random();
Now, use the Next() method to get random numbers in between a range −
r.Next(10,50);
The following is the complete code −
Example
using System;
public class Program {
public static void Main() {
Random r = new Random();
int genRand= r.Next(10,50);
Console.WriteLine("Random Number = "+genRand);
}
}Output
Random Number = 24