oculus42 / short-uuid

Translate standard UUIDs into shorter formats and back.
MIT License
450 stars 13 forks source link

How can I guarantee uniqueness of the shortened uuid? #62

Closed benknight closed 2 years ago

benknight commented 2 years ago

Hello, I have a question. How can I be certain about the uniqueness of my short uuids? For example what if I provide an alphabet that's very short, for example:

const translator = short('01');
wparad commented 2 years ago

The library only translates a uuid.v4() from base16 to baseN where N is your character list length. So in essence your question is:

How can I be certain about the uniqueness of uuid v4?

Right?

benknight commented 2 years ago

I think I understand now, basically the shorter the alphabet, the longer the translated result will be, for example:

const translator = short('01');
translator.fromUUID('e451eea2-5e52-440c-9a5b-06ce2362cef4');
// Result: 11100100010100011110111010100010010111100101001001000100000011001001101001011011000001101100111000100011011000101100111011110100