Users Online

· Guests Online: 23

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C# Program to Generate Random Numbers

C# Program to Generate Random Numbers

 

This is a C# Program to generate random numbers.

Problem Description

This C# Program Generates Random Numbers.

Problem Solution

Here random numbers are generated using the Random class and the next() in it.

Program/Source Code

Here is source code of the C# Program to Generate Random Numbers. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 * C# Program to Generate Random Numbers
 */
using System;
class Program
{
    static void Main()
    {
        Console.WriteLine("Some Random Numbers that are generated are : ");
        for (int i = 1; i < 10; i++)
        {
            Randfunc();
        }
    }
    static Random r = new Random();
    static void Randfunc()
    {
        int n = r.Next();
        Console.WriteLine(n);
        Console.ReadLine();
    }
}
Program Explanation

In this C# program using for loop we are calling the Randfun() function. Create the random variable object ‘r’, then using ‘n’ variable we are calling the next() function. Print the random numbers.

 
Runtime Test Cases
 
Some Random Numbers that are generated are : 
1234567
8754352
9864930
8352048
1920472
2846104
7649207
4928756
9261746

 

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 2.71 seconds
14,558,355 unique visits