Tuesday, 27 November 2012

Random Number Generator using Asp.net with C#



Using this class you can generate random numbers like passwords and identificators, but the main feature is that you can customise it to fit your needs. To do that you don't need to modify the code, it's enough to set some settings and you'll change the behavior of the generator.

Write the following classes in your C# Page,
int RandNo = 0;

private int RandomNumber(int min, int max)
        {
            Random random = new Random();
            return random.Next(min, max);
        }

Then call the following method where ever you require,
protected void Page_Load(object sender, EventArgs e)
        {
            RandNo = RandomNumber(10000000, 99999999);
            Response.Write(RandNo);
        }

Enjoy the coding...

No comments:

Post a Comment