Generate UUID v7

How UUID v7 works?

UUID version 7 provides a time-ordered value derived from the Unix Epoch timestamp, along with improved entropy characteristics. It is recommended over versions 1 and 6 when possible.

UUID v7 Structure

The 128-bit UUID v7 is organized as follows:

xxxxxxxx-xxxx-7xxx-yxxx-xxxxxxxxxxxx
  • xxxxxxxx-xxxx: 48-bit Unix Epoch timestamp (milliseconds since midnight, 1 Jan 1970 UTC, leap seconds excluded).
  • 7: Version number (7).
  • y: Value ensuring RFC 4122 variant.
  • xxxxxxxxxxxx: Remaining bits with random data.

UUID v7 Generation

  1. Create Timestamp: Utilize the Unix Epoch timestamp in milliseconds as the starting point.
  2. Set Version and Variant: Bits set to 0110 for version 7, and the variant according to RFC 4122.
  3. Generate Random Values: Create rand_a and rand_b, totaling 74 bits of pseudo-random data, for increased uniqueness.
  4. Assemble UUID: Combine the fields to form the 128-bit UUID.

Benefits of UUID v7

  • Time-Sortable: Uses a widely-accepted timestamp source, ensuring natural time-based sorting.
  • Improved Uniqueness: The inclusion of 74 bits of random data ensures a higher level of uniqueness.
  • Compatibility: Encourages use over previous time-based versions 1 and 6.

Bulk UUIDv7 generation

How many