The following code shows you how to generate a random integer number.
randomInteger() function generates a random number and displays on Console.
7
3
randomInteger() function generates a random number and displays on Console.
Code
public void randomInteger()
{
Random r = new Random();
for (int i = 0; i < 5; i++)
{
Defining r.Next(minValue, maxValue) means generating a random value between the mentioned boundaries. Here is just defining 1 to 10.
int num = r.Next(1, 10);
Console.WriteLine(num);
}
}
Output of the program is: (First Time Execution):
1
2
67
3
Output of the program is: (Second Time Execution):
7
1
9
8
2
So you see , numbers are generated in between 1 and 10.
0 comments:
Post a Comment