How can I always generate a 17 character unique alphanumeric data with c#.
Share
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.
Generate new Guid, and divide it 17 times by modulo 62. Each number you get is an index in char array described above (“abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW XYZ1234567890”).
By using Guid you can guarantee that your value is as unique as Guid is.
If you are concerned with losing unique bits you may hash GUID with MD5 like this:
UPDATE Guid format
According to this document (RFC 4122) and comparing with GUIDs generated by C#, they are of random type.
This type has the following pattern:
xxxxxxxx-xxxx-4xxx-Vxxx-xxxxxxxxxxxx, wherexis random number andVis a number with bit layout as 10yy, where yy are two random bits.So, here we have 122 random bits out of 128. So, in terms of uniqueness the Guid is simply a large random number and you are free to use any other random-number-generation algorithm that is capable to produce 88-bit random number (for example
RNGCryptoServiceProvider).Of course the method used to generate Guids may change in future versions of framework, but at the moment the Guid.NewGuid() looks like cheap random number generator in terms of code.