UUID v4 Generator - Random Unique Identifier Creator
Generate RFC 4122 compliant UUID version 4 identifiers using cryptographically random numbers. Free online tool for developers.
Understanding UUID Version 4
UUID v4 is the most commonly used UUID version, generating identifiers based entirely on random (or pseudo-random) numbers. Each UUID v4 contains 122 random bits, providing an astronomically low probability of collision—roughly 1 in 5.3 × 10^36.
This makes UUID v4 perfect for generating identifiers in distributed systems where coordination between nodes is impossible or impractical.
UUID Version Comparison
- v1 (Time-based): Uses timestamp + MAC address. Reveals creation time and hardware.
- v2 (DCE Security): Similar to v1 with POSIX UID/GID. Rarely used.
- v3 (MD5 Namespace): Deterministic hash from namespace + name using MD5.
- v4 (Random): 122 random bits. Most popular. Privacy-preserving.
- v5 (SHA-1 Namespace): Like v3 but uses SHA-1 instead of MD5.
- v6 (Reordered Time): New standard. Time-sortable variant of v1.
- v7 (Unix Epoch Time): New standard. Time-sortable with millisecond precision.
UUID v4 Structure
A UUID v4 follows this format: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
- Total length: 36 characters (32 hex digits + 4 hyphens)
- Bits: 128 total (122 random + 4 version + 2 variant)
- The "4": Version indicator at position 13
- The "y": Variant indicator (8, 9, a, or b) at position 17
When to Use UUID v4
Primary Keys
UUID v4 makes excellent primary keys for databases, especially in distributed systems or when you need to generate IDs client-side before inserting records.
API Resource Identifiers
REST APIs often use UUID v4 for resource URLs because they're unpredictable (security benefit) and unique across services (microservice-friendly).
Session and Token IDs
The randomness of UUID v4 makes them suitable for session identifiers and temporary tokens where unpredictability is important.
UUID v4 vs Sequential IDs
Trade-offs to consider when choosing between UUIDs and auto-increment integers:
- Storage: UUIDs use 16 bytes vs 4-8 bytes for integers.
- Index Performance: Random UUIDs cause more index fragmentation.
- Distribution: UUIDs work across distributed systems; integers need coordination.
- Security: UUIDs don't reveal record counts or creation order.
- Debugging: Sequential IDs are easier to work with during development.
Generating UUIDs in Code
- JavaScript (modern):
crypto.randomUUID() - Python:
str(uuid.uuid4()) - Java:
UUID.randomUUID().toString() - Ruby:
SecureRandom.uuid - Go:
uuid.New().String() - PostgreSQL:
gen_random_uuid()