Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Random string generation
Message
From
20/10/2010 10:14:43
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 4.0
Application:
Web
Miscellaneous
Thread ID:
01486288
Message ID:
01486310
Views:
44
>>Hi all,
>>
>>I need to generate a random string with a set length to use for creating a login account and and linking it to an exisiting customer account. Since I need to be able to differentiate it from another random generated string it would be nice if I could generate numerous strings from the same base value or something.
>>
>>What is the best way to do this? I am thinking somewhere between 10 and 15 characters is sufficient for this.
>>Thanks
>>Tim
>
>Coffee break solution:
Random r = new Random();
>            StringBuilder sb = new StringBuilder();
>            string[] a = "A B C D E F a b c d e f".Split();
>            for (int i = 0 ; i < 15 ; i++)
>            {
>                sb.Append(a[r.Next(0,a.Length)]);
>            }
>            string result = sb.ToString();
Add to a[] to allow bigger choice of characters.....


Hi Viv & Cetin,

Thanks for the simple examples. I will check these out but looks like I can get exactly what I need.
Tim
Timothy Bryan
Previous
Reply
Map
View

Click here to load this message in the networking platform