UUID v4 or v7?
| v4 | v7 | |
|---|---|---|
| Made from | 122 random bits | 48-bit timestamp in milliseconds, then 74 random bits |
| Sorts by creation time | No | Yes |
| As a database primary key | Inserts land all over the index | New rows go at the end of the index, like an auto-increment ID |
| Reveals when it was made | No | Yes, to the millisecond |
Use v7 for primary keys and anything you want to sort by age. Use v4 when the ID must not leak its creation time, for example in a public link.
The 13th hex digit is the version, so a v4 UUID always reads xxxxxxxx-xxxx-4xxx-… and a v7 reads …-7xxx-….
How strong is a random string?
Strength is measured in bits: length × log2(number of possible characters). The page shows this number under the output.
| Characters | Set size | Length for about 128 bits |
|---|---|---|
| Digits only | 10 | 39 |
| Lowercase and digits | 36 | 25 |
| Upper, lower and digits | 62 | 22 |
| With symbols | 85 | 20 |
For API keys and session tokens, 128 bits is a sensible floor.
Questions
Are these values really random?
They come from crypto.getRandomValues, the browser's cryptographic generator, not from Math.random. Characters are picked so that each one is equally likely.
Can two UUIDs collide?
In theory. In practice you would need to generate about 2.7 quintillion v4 UUIDs before a collision becomes likely.
Are the generated values stored anywhere?
No. They exist only in this tab and are gone when you reload it.