lithammer / shortuuid

:mushroom: A generator library for concise, unambiguous and URL-safe UUIDs

Home Page:https://pkg.go.dev/github.com/lithammer/shortuuid/v4

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The returned UUID length is not consistent

Mido-sys opened this issue · comments

@lithammer,

Randomly, the generated UUID length returned using shortuuid.New() is 21 instead of 22.

I suspect this is related to #23

@lithammer,

Thank you so much for the speedy reply :-)

Yes, that might be the issue. Any ET when the pull request can be merged?

I have another solution in mind (basically port upstream changes from the Python library). But that means a breaking change since you wouldn't be able to decode uuids created from v3 using. So I would have to make a major version change.

An upside is that the length will be consistent and use fewer allocations (i.e. be faster).

I'm curious though what the problem you face with inconsistent string length?

I've merged GH-29 and released v4.0.0. So please migrate to github.com/lithammer/shortuuid/v4 for consistent length (and some other improvements).

And sorry for the inconvenience of having to make a major version bump.

@lithammer, apologies for the late reply.

We have been using v4 for a while now, and the length has been consistent. Thank you.

We're using it as a request ID, and the length wasn't correct when we tried to validate the ID. BTW, how unique are the generated UUID? We faced issues having duplicates generated.

BTW, how unique are the generated UUID? We faced issues having duplicates generated.

Hmm that's surprising given that the chance of a collision is extremely low for a UUIDv4 (which is what's used under the hood). Unless maybe the server(s) have very low entropy or something similar...? 🤔

Wikipedia contains a section about this: https://en.wikipedia.org/wiki/Universally_unique_identifier#Collisions