I want to generate a 9 digit unique random string. Currently I am using
Guid.NewGuid().ToString().Replace("-","").Substring(0,9)
But I am afraid it would have a collision very soon. Is there any better way for this or would this be OK?
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 take a sub string of a GUID you are not guaranteed
randomnessuniqueness at all.See my answer to a older SO question to fulfill your randomness requirement. Here is the basic code to do it.
it gives you 12 digits of counting to prevent collisions and any additional digits you want of randomness. you can modify the code as you want to make shorter than 12 digit strings.