How to Generate Random Integer number in Visual C#

In Visual Studio we can generate random Integer number by using a class called Random, in the program we are going to make we are using Next Method with two arguments(Min and Max).

First we need to create the new random object, 
declare the integer variable with next method, 
and print it to the console.
Okay, let’s do the real thing, We are going to make three random number between 0 to 14

static void Main(string[] args)


//New Random Class
         Random rnd = new Random();
         int a,b,c; 
//Next method inside a variable with Min and Max Arguments
a = rnd.Next(0, 15); //with Min 0 and Max 15, then it will randomly generate 0-14.
b = rnd.Next(0, 15);
c = rnd.Next(0, 15);



The Output Will be…
Press any key to continue . . .
Okay, and this is the second time I debug
Press any key to continue . . .

See that? The numbers are different!
Hope it will help in your future coding 🙂

Leave a Reply