Display random number in c#

Again a small tip, How to display n digit random numbers in ASP.NET using c# ? Its a bit simple you need to call Random class to generate numbers with minimum and maximum limits of digits (numbers).

the code is as Follow:

Code Snippet
  1. protected void Page_Load(object sender, EventArgs e)
  2.     {
  3.         int ranid = RandomNumber(10000, 99999);// can pass minium and maximum number for random number generation.
  4.         Label1.Text = ranid.ToString();
  5.     }    
  6.     private int RandomNumber(int min, int max)
  7.     {
  8.         Random random = new Random();
  9.         return random.Next(min, max);
  10.     }

A small tip but may be helpful for new ones……

Thanks….

5 Comments

Comments have been disabled for this content.