I am willing to take a greater risk of collisions for a shorter uuid.
right now I have this:
"file:///home/node/.docker_r2g_cache/83cd49f2-45ba-49ec-9b72-6f84a8adeec7/residence"
I am looking for something more like:
"file:///home/node/.docker_r2g_cache/6f84a8adeec7/residence"
can this library do that or should I use another lib? any recommendations? thx
The shorter you make your nonce, the more likely you are to run into collisions. If you know how many unique keys you need, you can calculate the odds: look up “Birthday Paradox”. If you’re OK with the odds, it’s easiest to take a slice of the last ten hex digits of a v4. If you need more bits, take care to not use the bits that indicate which kind of UUID you have: those aren’t random.
I'd suggest using another lib. This lib is specifically for creating RFC4122 UUIDs, which have a specific syntax. If all you care about is length of id, then you'll want one that draws from a larger set of chars than the 16 hex digits.
Something like https://www.npmjs.com/package/shortid, perhaps? A 21-char id from that lib should have roughly the same chance of collision as the 36-char v4 UUID from this lib.
thanks all, I asked this question on shortid:
https://github.com/dylang/shortid/issues/119
I currently am using the 8 char id, which I calculate 2 given ids as having about 1 in 4trillion chance of colliding.
Careful. The odds of collision increase dramatically as you generate more ids. Commented on that shortid issue with details.
@broofa yeah I am not generating that many ids, less than 20 that can collide at any time, never more than 20 different ids that could collide with one another. that's why I am willing to risk collision, because the niceness/readability of short ids is useful for users.
Most helpful comment
I'd suggest using another lib. This lib is specifically for creating RFC4122 UUIDs, which have a specific syntax. If all you care about is length of id, then you'll want one that draws from a larger set of chars than the 16 hex digits.
Something like https://www.npmjs.com/package/shortid, perhaps? A 21-char id from that lib should have roughly the same chance of collision as the 36-char v4 UUID from this lib.