C# Program to Generate Random Number And Random String – Programming, Pseudocode Example, C# Programming Example
C# C# Console

C# Program to Generate Random Number And Random String

In this example we’ll learn how to Generate Random Number And Random String in C#.

Random class constructors have two overloaded forms. It takes either no value or it takes a seed value. The Random class provides Random.Next(), Random.NextBytes(), and Random.NextDouble() methods. The Random.Next() method returns a random number, Random.NextBytes() returns an array of bytes filled with random numbers, and Random.NextDouble() returns a random number between 0.0 and 1.0. The Random.Next() method has three overloaded forms and allows you to set the minimum and maximum range of the random number. The following code returns a random number. 

The following code returns a random number less than 100.

 The following code returns a random number between the min and the max range.

You can even combine the two methods – RandomNumber and RandomString to generate a combination of random string and numbers. 

Here is the complete code:

Output:

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.