Pages

Search This Blog

Friday 9 May 2014

Creation of random number in asp.net

Hi friends, “In this is session I will show you how to generate a random number”.

Many of us can assign a unique id for different users. In some applications we need to generate a password in such cases we can use this random function. So burden on you reduces so much.

*We write this code in filename.aspx.cs

Random rand = new Random();

Example:

string s = "";

Random random = new Random();
int length = 8;

   for (int i = 0; i < length; i++)
     {
  
     if (random.Next(0, 3) == 0)              
      
      //if random.Next() == 0 then we generate a random character
                {
                    s += ((char)random.Next(65, 91)).ToString();
                }
       
         else                                           
      
      //if random.Next() == 0 then we generate a random digit
                {
                    s += random.Next(0, 9);
               }

       }

You can rate my class on right side top of my blog ....

                                                                         -Your's Santoshklpkl

No comments:

Post a Comment

Animated Social Gadget - Blogger And Wordpress Tips Twitter Bird Gadget