Quick code to generate unique base62 hashes

Hi guys I want to generate unique base62 hashes - something similar to what tinyurl and bit.ly do with C #. this will be based on the auto-increment field id of type bigint (like most of these sites).

min chars will be 1 and max chars will be 6 ... if you needed to write the fastest code (least CPU usage) in C # for this hash, how would you write it?

+2


source to share


2 answers


Please see my answer to another question, which is similar, here:

Need a smaller GUID alternative for the database ID, but still unique and random for the URL

I posted a C # class called "ShortCodes" which does exactly what you are looking for, that is, generate a unique baseX (where X is whatever!) Hash based on an integer / long number and also for back conversion.



I actually wrote this little class precisely to simulate the shortcode / hash generation of sites like TinyUrl.com and Bit.ly for my own purposes.

I can't tell if this is the absolute fastest way to achieve this, but it's not too slow! :)

+3


source


Eric Lippert suggested lookup tables in a similar question earlier. His answer is perfect for your purposes.



0


source







All Articles