A version-4 UUID is 122 bits of randomness plus 6 fixed bits:
- 16 random bytes are drawn from
crypto.getRandomValues()— the browser's cryptographically secure RNG. - Byte 6 is masked to
0100in its high nibble (the version digit — always4). - Byte 8 is masked to
10xxin its high bits (the RFC 4122 variant). - The bytes are rendered as 32 hex digits in the
8-4-4-4-12pattern, e.g.xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxxwhereyis 8, 9, a or b.
With 122 random bits, the chance of two generated UUIDs colliding is negligible for any practical purpose.