What is UUID v4?
UUID v4 fills 122 of its 128 bits with random data (the remaining 6 bits mark the version and variant). Because the value is purely random, no information about when or where it was created can be inferred from it — a privacy advantage over timestamp-based versions.
When should I use v4?
Use v4 whenever you just need a unique identifier: request IDs, session tokens' identifiers, resource IDs in APIs, file names. If your IDs will be used as database primary keys and insert order matters, consider UUID v7 instead — its time-ordered layout keeps database indexes efficient.
How likely is a collision?
With 122 random bits, you would have to generate roughly 2.7 quintillion UUIDs to reach even a 50% probability of one collision. For practical purposes, v4 UUIDs can be treated as globally unique.
Need a different version? Try the full UUID generator supporting v1, v3, v4, v5 and v7.