On Mar 17, 3:15 pm, Daniel Pitts
<newsgroup.spamfil...@virtualinfinity.net> wrote:
Angelo Chen wrote:
On Mar 17, 8:09 pm, Sabine Dinis Blochberger <no.s...@here.invalid>
wrote:
angelochen...@gmail.com wrote:
I use UID to generate a unique number in a server app, here is my
code:
UID inviteId = new UID();
String uid = new sun.misc.BASE64Encoder().encode(inviteId.toString
().getBytes());
sample output:
NjhkZmMyNDQ6MTIwMTQ0YTYwMDk6LTgwMDA=
I'd like to have a unique string consists of normal characters, not
sings like = and others, any hint on this? Thanks,
A.c
p.s. normal character set, i meant A to Z, a to z, 0..9
You only want alpha-numeric characters.
You want to look into hashing, not encoding. Did you use BASE64Encoder
without looking up what it's for?
Thanks, will give md5 hash a try, the = sign was acceptable before,
but now no more in the new situation. just a related question, a
unique string will always generate a unique md5 hash?
No, Hashes are never guaranteed to be unique, but the good ones have a
"very low" chance of collision.
Just to nitpick...
You seem to be talking about "Hashes" (with an uppercase 'H') in
general, so I'd argue that a perfect hash is a hash, that a perfect
hash is a good hash and that perfect hashes are guaranteed to be
unique and have zero chance of collision.
So I find that saying: "No, Hashes are never guaranteed
to be unique, but the good ones have a very low chance
of collision" isn't entirely correct and doesn't tell the
whole story about Hashes [sic].
If you need absolutely unique, hash is the wrong way to go.
I'd reword that to:
The hash produced by Java's String hashcode() method is the
wrong way to go in the OP's case.
A perfect hash would be unique and in many case perfect hashes
or minimal perfect hashes are the way to go.
Just my 0.02 nitpick for I just considerably speeded some
process by rewriting a binary search that was happening at
some point by a "one-table-lookup-no-collision" using a
minimal perfect hash ;)
to have as much information in it as the original data. As was
your hash space is smaller than your data space.
your hash space.