Does anybody know any algorithm which generates unique 8 or 9 digits number for a given string? It would be better to have a php example also if not then at least the algorithm.
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.
You could use crc32() and return the len.
Edit
After doing a collision/reliability test against my answer, its likely you will get collisions for length 8 and perhaps slightly less for 9 and then even less for 10 ect. In my test I tested an incrementing value from 0 to 100k and there were 26 collisions, the first happens a 36k.
Test result:
Conclusion is that unless you do a 1 for 1 increment on a auto incrementing value your always get collisions for the same byte length and more as you fill your users table:
You can work around this by adding another byte to the collided value or include the a-z range like with md5()/sha() hash functions tho that defeats the object ;p
Good luck