Using Random Class to Generate Random Numbers in C#:
Here, You will learn how to use Random Class in C# to generate Random numbers. You can use this techniques in games or Programs in which you require some uniqueness. I Personally use this Class in Ludo Game to generate the Dice Outputs.
You can do a number of works by this Class but I am explaining to Generate the Random Numbers.
Code to Generate Random Numbers:
Random random = new Random(); // Making object of Random Class
for (int i = 0; i < 5; i++) // Counter Loop to show result
{
int number = random.Next(1, 7); // Generating Random Number from 1 to 6 to use in ludo
Console.WriteLine(number); // Writing the output on Console Screen...
}
Output:
Commenting on a post is a great way to show some love for what you're seeing.