生成唯一标识符(UUID) v1(基于时间戳)和v4(基于随机)。
A UUID (Universally Unique Identifier), also known as GUID (Globally Unique Identifier), is a 128-bit identifier that is unique across space and time. The standard representation is 32 hexadecimal digits displayed in five groups separated by hyphens (e.g., 550e8400-e29b-41d4-a716-446655440000).
There are several UUID versions with different generation methods. UUID v1 uses timestamp and MAC address. UUID v4 uses random numbers and is most commonly used. UUID v3 and v5 use namespace and name hashing. Each version has specific use cases based on uniqueness requirements and privacy considerations.
While collisions are theoretically possible, the probability is astronomically low (1 in 2^122 for v4). You would need to generate 1 billion UUIDs per second for 85 years to have a 50% chance of collision.
Use v4 for most cases as it doesn't reveal any information. Use v1 if you need time-sortable IDs and don't mind exposing creation timestamps.