How to create random X-length string that contains letters and numbers. My fast solution is:
Guid.NewGuid().ToString("N").Substring(X);
Any another better ideas?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you want “random” strings for dictionary keys, simply use a
Guid. They will be unique and more than adequate for keying dictionaries.Something like would work, but you need to constrain your random range to avoid shenanigans:
Warning, coded it and ran it once – otherwise untested. Performance versus your current solution is unquantified. Also, this implementation is a lot wordier than the answer linked in the question comments.
There’s probably a nicer way to do this using the ASCII codes, but meh.