Random Generators

Pembuat UUID

Hasilkan pengidentifikasi unik untuk proyek pengembangan

Pengaturan Generator
Konfigurasi opsi pembuatan UUID
UUID yang Dihasilkan
Hasilkan pengidentifikasi unik

Tidak ada UUID yang dihasilkan. Konfigurasikan pengaturan dan hasilkan!

Usage Examples

JavaScript/TypeScript

// Example usage
const userId = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
const sessionId = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"

Database Schema

-- SQL example
CREATE TABLE users (
  id UUID PRIMARY KEY,
  name VARCHAR(255)
);
UUID Structure Breakdown
Understanding the anatomy of UUIDs

UUID v4 (Random) Structure

xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
32 bits - Random data (time_low field)
16 bits - Random data (time_mid field)
4 bits - Version (always 4)
12 bits - Random data (time_hi field)
2 bits - Variant (always 10 binary)
6 bits - Random data (clock_seq_hi)
8 bits - Random data (clock_seq_low)
48 bits - Random data (node field)
Total: 128 bits
• 4 bits for version identifier
• 2 bits for variant identifier
• 122 bits of random data
• Field names follow RFC 4122 layout but contain random data in v4

UUID v7 (Time-ordered) Structure

xxxxxxxx-xxxx-7xxx-yxxx-xxxxxxxxxxxx
48 bits - Unix timestamp (milliseconds since epoch)
4 bits - Version (always 7)
12 bits - Sequence counter (sub-millisecond ordering)
2 bits - Variant (always 10 binary)
62 bits - Random data
Total: 128 bits (RFC 9562)
• 48-bit timestamp provides millisecond precision until year 10889
• 4 bits for version identifier
• 12-bit sequence counter enables 4,096 UUIDs per millisecond
• 2 bits for variant identifier
• 62 bits of random data for collision resistance
Sequence Counter Behavior:
• Ensures ordering for UUIDs generated within the same millisecond
• Resets to random value when timestamp advances
• Increments for each UUID within the same millisecond
• Handles overflow by advancing timestamp artificially

Sequence Counter & Ordering

UUID v4: No inherent ordering - each UUID is completely random. Lexicographic sorting produces unpredictable order, making them unsuitable for time-based queries.
UUID v7: Natural chronological ordering based on generation timestamp. The 48-bit timestamp ensures UUIDs sort by creation time, while the 12-bit sequence counter handles multiple UUIDs generated within the same millisecond.
Database Impact: v7 UUIDs reduce index fragmentation and improve INSERT performance because new records are always appended in chronological order, unlike v4 which causes random insertions.
Sequence Counter Details: When multiple UUIDs are generated within the same millisecond, the counter increments to maintain strict ordering. If the counter overflows (>4,095), the timestamp is artificially advanced to the next millisecond.
UUID Version Comparison
Choose the right UUID version for your needs
FeatureUUID v4 (Random)UUID v7 (Time-ordered)
Generation Method122 bits cryptographically random data48-bit timestamp + 12-bit counter + 62-bit random
SortabilityRandom order, no temporal relationshipChronologically sortable by generation time
Database PerformanceIndex fragmentation, random INSERT locationsSequential INSERTs, reduced fragmentation
Use CasesGeneral purpose, maximum entropy, securityTime-series, logs, events, ordered data
PrivacyNo timing information leakedCreation timestamp visible (privacy concern)
Collision Resistance2^122 possible values (extremely high)2^62 per millisecond (very high)
RFC StandardRFC 4122 (widely supported)RFC 9562 (newer, growing support)
Tips & Use Cases
Master unique identifier generation for your projects

Perfect Use Cases

  • Database primary keys: Distributed systems, avoid auto-increment conflicts
  • API identifiers: Public-facing IDs that don't reveal record counts
  • Session tokens: User sessions, temporary authentication (v4 preferred)
  • File naming: Unique filenames, document versioning, media uploads
  • Microservices: Request tracing, correlation IDs, service communication
  • Event sourcing: Event IDs, command tracking (v7 for chronological order)
  • Cache keys: Distributed caching, temporary resource identification
  • Testing data: Reproducible test fixtures, mock data generation

Best Practices

  • Version choice: v4 for security/privacy, v7 for performance/ordering
  • Database storage: Use BINARY(16) or native UUID types, not VARCHAR
  • Indexing strategy: Clustered indexes work better with v7 than v4
  • Format consistency: Standardize on dashed/compact across your system
  • Case sensitivity: Choose uppercase or lowercase consistently
  • Validation: Always validate UUID format at API boundaries
  • Privacy consideration: v7 leaks creation time, use v4 for sensitive data
  • Performance: Generate UUIDs client-side to reduce server load
Frequently Asked Questions

What's the difference between UUID versions?

Version 4 is randomly generated and most common for general use. Version 7 includes timestamp for natural sorting while maintaining randomness. V4 is perfect for general purposes, while V7 is ideal when you need chronological ordering or time-based partitioning.

When should I use UUID v7 over v4?

Use UUID v7 when you need time-ordered identifiers for better database performance, natural sorting, or time-based partitioning. V7 UUIDs sort chronologically and can improve INSERT performance in databases. Use v4 when you need maximum randomness and don't care about ordering.

How does UUID v7 maintain uniqueness while being time-ordered?

UUID v7 uses a 48-bit timestamp (milliseconds since Unix epoch), a 12-bit sequence counter, and 62 bits of random data. This ensures chronological ordering while maintaining extremely low collision probability. The timestamp portion allows natural sorting, the sequence counter handles multiple UUIDs within the same millisecond, and the random suffix prevents conflicts.

What are the benefits of UUID v7 for databases?

UUID v7 improves database performance by reducing index fragmentation since new records are inserted in chronological order. This leads to better INSERT performance, more efficient range queries, and improved cache locality. It's particularly beneficial for time-series data and audit logs.

Are UUIDs truly unique across all systems?

Version 4 UUIDs have a collision probability so low (1 in 5.3x10^36) that they're considered practically unique. The chance of generating a duplicate is negligible even across billions of systems generating millions of UUIDs per second.

Should I use UUIDs or auto-incrementing integers?

Use UUIDs when you need distributed systems compatibility, want to avoid exposing record counts, or need offline generation. Use integers for better performance, smaller storage, and when you need sequential ordering. UUIDs are better for APIs and microservices.

What's the performance impact of using UUIDs?

UUIDs are larger (128 bits vs 32/64 bits for integers) and slower to index. However, the performance difference is usually negligible for most applications. Store as binary rather than strings in databases for better performance and consider clustered indexes.

Can I use UUIDs for security purposes?

UUIDs provide obscurity but aren't cryptographically secure. Don't rely on them for authentication tokens or security-critical applications. Use proper cryptographic methods for security. UUIDs are good for preventing enumeration attacks on public IDs.

How do I store UUIDs efficiently in databases?

Store as BINARY(16) or UUID native types rather than VARCHAR(36) to save space and improve performance. Use proper indexing strategies and consider partitioning for very large tables. Some databases have specific UUID functions for optimal handling.

What's the difference between UUID v1, v4, and v7?

UUID v1 uses MAC address and timestamp (privacy concerns), v4 is purely random (most common), and v7 uses timestamp with random suffix (newest, best for databases). v4 is recommended for general use, v7 for time-ordered applications.

Can UUID v7 reveal sensitive timing information?

Yes, UUID v7 contains a millisecond-precision timestamp that reveals when it was generated. This could be a privacy concern for sensitive applications. Use UUID v4 when creation time should remain private.

How many UUIDs can I generate per second with v7?

UUID v7 can generate up to 4,096 unique UUIDs per millisecond (due to the 12-bit sequence counter), which equals over 4 million UUIDs per second. When the counter overflows, the timestamp advances to maintain uniqueness.

API Documentation
Generate UUIDs programmatically
GET/a/v1/uuid

Generate universally unique identifiers

Parameters:

count (integer, 1-500): Number of UUIDs (default: 1)
version (integer): UUID version 1, 4, or 7 (default: 4)
format (string): standard, compact, urn (default: standard)
uppercase (boolean): Use uppercase letters (default: false)

Example Request:

curl -H "Authorization: Bearer YOUR_API_KEY" \
  "https://random-generators.com/a/v1/uuid?count=3&version=4&format=compact"

Example Response:

{ "success": true, "data": [ "550e8400e29b41d4a716446655440000", "6ba7b8109dad11d180b400c04fd430c8", "6ba7b8119dad11d180b400c04fd430c8" ], "version": 4, "format": "compact", "credits_used": 1 }