"Malcolm McLean" <re*******@btinternet.comwrites:
"joe" <jc*****@gmail.comwrote in message
news:af**********************************@m23g2000 hsc.googlegroups.com...
>Hello anyone knows how to write a funtion to genereate a tiny url with
letters and numbers only. Something almost always unique. THanks.
It's inherently impossible to collapse 36^N unique URLs to 36^(N/4)
unique tiny urls.
However there's a hash function on my websites. It's in one of the
free chapters under Basic Algorithms. I recommend that you split the
string into 2, and generate 2 unsigned longs. The chance of a
collision is so low as to be negligible.
I have a feeling this is a bad idea[1]. The Bernstein hash function
(which is the one on your) site uses unsigned long but will work just
as well with any unsigned integer type. If the OP has access to
longer integers, it seems safer to simply use a longer integer that
than generate two hashes from two parts of the string.
[1] I have no formal argument in support of this, just the feeling
that, since URLs often have similar parts you are wasting the hash
function's mixing ability if you split the string. Anyway, even if
there is no reason to worry here, why take the risk -- unless, of
course, you don't have longer integer types.
--
Ben.