Cách Tạo UUID Từng Bước Một
Quick Answer
Để tạo UUID: mở UUID Generator, chọn phiên bản 4 (random) và nhấn Generate. Công cụ tạo UUID như "550e8400-e29b-41d4-a716-446655440000" dùng crypto.getRandomValues. Tất cả tạo xảy ra cục bộ.
Introduction
UUID (Universally Unique Identifier) là định danh 128-bit thực tế đảm bảo duy nhất không cần phối hợp giữa các bên. UUID được dùng phổ biến as primary key cơ sở dữ liệu, request ID, session token và định danh hệ thống phân tán. Phiên bản phổ biến nhất là UUID v4, dùng bit ngẫu nhiên.
Step by Step
-
Open the UUID Generator tool
Go to the UUID Generator tool page. The tool supports UUID v4 (random) and v1 (time-based) generation.
-
Select the UUID version
Choose UUID v4 for most use cases — it uses cryptographically secure random bits and has no privacy concerns. Choose v1 only if you need time-ordered IDs and accept the privacy tradeoff (v1 embeds a timestamp and MAC address).
-
Choose the quantity
Set how many UUIDs you want to generate — from 1 to 1000. Generating multiple UUIDs at once is useful for seeding a database or creating batch request IDs.
-
Generate the UUIDs
Click Generate. The tool produces UUID(s) using crypto.getRandomValues for v4, ensuring cryptographic randomness. Each UUID is a 36-character string in the format 8-4-4-4-12 hex digits.
-
Copy the UUID(s)
Click Copy to copy a single UUID, or copy the entire list if you generated multiple. Use the UUID as a database ID, request correlation ID, or session token.
Examples
UUID v4 (random)
Input: Version: 4, Quantity: 1
Output: 550e8400-e29b-41d4-a716-446655440000
Multiple UUID v4
Input: Version: 4, Quantity: 3
Output: f47ac10b-58cc-4372-a567-0e02b2c3d479
7b582ea2-1f4d-4f6a-9c83-3a5f2b8e1d47
3d4a5b6c-7e8f-4a2b-9c1d-0e3f5a7b9c2d
UUID v1 (time-based)
Input: Version: 1, Quantity: 1
Output: a3bbf0ee-d6e4-11ed-a5b3-3c9703e8b4a1
Common Problems
- Using Math.random() to generate UUIDs —it is not cryptographically secure. Always use crypto.getRandomValues() or crypto.randomUUID().
- Storing UUIDs as strings in databases —UUIDs stored as UUID type (16 bytes) are more efficient than strings (36 bytes).
- Using v1 in security-sensitive contexts —v1 embeds a timestamp and MAC address, which can leak information. Use v4 for anonymity.
- Assuming UUIDs are truly unique —they are practically unique (collision probability is negligible), but not guaranteed unique.
Tips
- Use UUID v4 for almost all use cases —it is random, has no privacy concerns, and is supported by all modern databases.
- Use crypto.randomUUID() in modern browsers for a built-in v4 generator without a library.
- Store UUIDs as UUID/GUID type in databases (16 bytes) instead of strings (36 bytes) for better storage and index performance.
- Use UUIDs as request IDs for distributed tracing —they correlate requests across services without central coordination.