| C# program that uses Random
Now we will learn how to use Random keyword and below synatx will help you to understand how and when to use Random keyword. This random event disrupts order. For this simulation, a random number generator could be used.
using System;
class Program
{
static void Main()
{
Random random = new Random();//Random Object
//These are always 1, 2, 3, 4 or 5.
//Get 3 random number in between 1 to 5
Console.WriteLine(random.Next(1, 5));
Console.WriteLine(random.Next(1, 5));
Console.WriteLine(random.Next(1, 5));
}
}
Output:-
2
1
4 | | |