Q:

C# program to generate random numbers

0

C# program to generate random numbers

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to generate random numbers in C# is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//Program to Generate Random Numbers in C#.

using System;

class RandomEx
{
    static void Main()
    {
        int num = 0;
        Random R = new Random();

        Console.WriteLine("Random Numbers: ");
        for (int i = 1; i < 10; i++)
        {
            num = R.Next();
            Console.WriteLine(num);    
        }
    }
}

Output:

Random Numbers:
1396315331
747908140
1390110439
2025904104
318255387
1630415135
455253731
1489207714
137356946
Press any key to continue . . .

Explanation:

In the above program, we created the RandomEx class that contains Main() method, In the Main() method we created the object R of Random class.

Console.WriteLine("Random Numbers: ");
for (int i = 1; i < 10; i++)
{
    num = R.Next();
    Console.WriteLine(num);    
}

Here we used the Next() method to generate random numbers and then print them on the console screen.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Basic Programs | Class, Object, Methods

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to take height as input and print its c... >>
<< C# program to demonstrate ATM transactions...