What the characters mean
A UUID looks like an arbitrary string of hex, but two positions are fixed. Take 3f2a91c4-8b7d-4e21-9c05-71ad3e9f0b28:
- The third group always starts with 4. That is the version, and it says this UUID was made from random bits rather than from a clock or a MAC address.
- The fourth group always starts with 8, 9, a or b. That is the variant, two fixed bits saying which UUID layout is in use.
Those six fixed bits are why a v4 UUID carries 122 bits of randomness rather than 128. It is a small difference and it makes no practical odds, but it is the sort of detail worth getting right rather than rounding up.
Identifiers, not secrets
A UUID is designed to be unique, not to be unguessable, and the distinction matters in practice. Unique means two systems can generate identifiers independently and never clash. Unguessable means the value can stand between an attacker and someone’s data. A v4 UUID happens to be both, because it is random — but everything around it treats it as an identifier.
That is where the trouble starts. Identifiers end up in server logs, in analytics, in URLs that get shared and in screenshots pasted into tickets. A value used as a password reset token should never be somewhere that happens to. If you want a secret, generate one on purpose with the random string generator and handle it like a password.
Uniqueness in practice
122 random bits is roughly 5.3 undecillion possibilities. The usual way to picture it: you would have to produce a billion UUIDs every second for about 86 years before the chance of any two matching reached a coin flip. In other words, generate all you like — collisions are not the thing that will go wrong with your system.
Where they come from here
Sixteen bytes from crypto.getRandomValues, then the version and variant bits are set, then the bytes are formatted as hex. No time, no counter, no machine identifier, and no network request. If the browser cannot provide a cryptographic random source, the page refuses to generate anything rather than fall back on something predictable.