How to Get AutoGenerate Code with Strings and Numbers in C#
-
Hi, This is from CHandra My Questions in How can i get AutoGenerate alpha numerics with combination of strings and Numbers. Can any give me some suggestion on or any code is there in C# please send me Thanks and Regards Chandrakanth
-
Hi, This is from CHandra My Questions in How can i get AutoGenerate alpha numerics with combination of strings and Numbers. Can any give me some suggestion on or any code is there in C# please send me Thanks and Regards Chandrakanth
How about...
string GetRandomString(int length)//length of random string
{
System.Text.StringBuilder sb = new System.Text.StringBuilder(length);
Random rnd = new Random();
for(int i = 0; i < length; i++)
{
sb.Append((char)rnd.Next(33, 127));
}
return sb.ToString();
}Life goes very fast. Tomorrow, today is already yesterday.
modified on Wednesday, July 15, 2009 9:08 AM
-
Hi, This is from CHandra My Questions in How can i get AutoGenerate alpha numerics with combination of strings and Numbers. Can any give me some suggestion on or any code is there in C# please send me Thanks and Regards Chandrakanth
-
How about...
string GetRandomString(int length)//length of random string
{
System.Text.StringBuilder sb = new System.Text.StringBuilder(length);
Random rnd = new Random();
for(int i = 0; i < length; i++)
{
sb.Append((char)rnd.Next(33, 127));
}
return sb.ToString();
}Life goes very fast. Tomorrow, today is already yesterday.
modified on Wednesday, July 15, 2009 9:08 AM
musefan wrote:
System.Text.StringBuilder sb = new System.Text.StringBuilder(length);
ftfy. I improved the performance a bit. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.