3 ms·
I've always been particular to pre-pending the current time (epoch, date, whatever) to the start of a UUID of some sort. Mathematically, you're actually more l
by mabbo 11y ago
I've always been particular to pre-pending the current time (epoch, date, whatever) to the start of a UUID of some sort.
Mathematically, you're actually more likely to generate collisions this way, but we're talking 0.00001% in a million years vs 0.001% in a million years. It won't happen either way, practically speaking.
And the benefit? It's usually easier to explain to other people. It's more intuitively safe because there would need to be two colliding keys generated the same second.
- darkxanthos 11y agoYup! I came here to post exactly this. Like you said, mathematically it isn't perfect but in reality it's basically rock solid. If space is a concern, this time stamp could also be converted into ascii or the like.
- twoodfin 11y agoHowever many bits you're using to store the timestamp would better guarantee uniqueness if they were random. Whether it's intuitively safer or not, it's empirically less safe. This is exactly why the UUID spec evolved into a pure random value.
- emcq 11y agoAgreed, but it can still be a useful technique if you ever need to sort your values by time, in which case it's logically a tuple masquerading as a physical single id.
- deathanatos 11y agoHow would pre-pending the date to a UUID increase the change of collision?