+92 332 4229 857 99ProjectIdeas@Gmail.com

Random Number Generator (C#.net)


Random Number Generator
The following code shows you how to generate a random integer number.
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
6
7
3

Output of the program is: (Second Time Execution):
7
1
9
8
 

So you see , numbers are generated in between 1 and 10.


Related Article:

Random String Generator

0 comments: