Generation of random alphanumeric string in C#

The following code snippet shows how to generate random alphanumeric string in C#.



using System;
using System.Text;

public string RandomString (Random r, int len)
{
string str
= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
StringBuilder sb = new StringBuilder();

while ((len--)> 0)
sb.Append(str[(int)(r.NextDouble() * str.Length)]);

return sb.ToString();
}


Comments

Author: Sam31 Oct 2008 Member Level: Bronze   Points : 1

HI
Shanthi M

Can you please check this link.....

http://www.eggheadcafe.com/software/aspnet/30271254/c-random-alphanumeric-st.aspx

If you copied some one code , provide link....

Thanks

Dontworry



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: