How to Generate Random Number in C#/CSharp

To generate a random number in C#/CSharp, we make use of Random class.  You can pass min and max value as parameter to its method called Next which will a generate number.  The generated number will be within a range from min value and less than max value.  This means max value will not be part of randomly generated number. Example is given below.

using System;

namespace Hello_World
{

    class Program
    {
        static void Main(string[] args)
        {
            Random rand = new Random();
            int number = rand.Next(1, 100);

            Console.WriteLine(number);
        }      
    }
}