Hacker News new | ask | show | jobs
by jupp0r 1134 days ago
In practice, I generate UUIDs entirely using entropy from /dev/random. The probability of a collision is really low for most use cases (although not if you are Google and need something unique across all database rows in your company or something similar).
1 comments

Hopefully you're setting the appropriate bits. A UUID is a bit-packed struct/union at heart, really; if you're just reading 128-bits of random data from /dev/random, that's not a UUID; passing it off as such would be needlessly confusing.

(It's fine to make a new format / it's not terrible approach for making a random ident, though you might want to peek into, e.g., ksuid from the OP for some interesting points about why you might not want to do that, plus some advice about getrandom() over /dev/random.)

The systemd developers made the same mistake initially. They later corrected it, and forced the non-random fields to the correct values.
If you treat them as opaque strings and don't use their binary representation, you'll be fine.