Class Overview
SIMPLE_UUID generates RFC 9562 compliant UUIDs. It supports UUID v4 (random)
and UUID v7 (timestamp-based), with full Design by Contract support.
Creation
Initialize the UUID generator with a time-based random seed.
Contracts
UUID v4 (Random)
UUID v4 uses 122 random bits, providing maximum uniqueness without timestamp information.
new_v4: ARRAY [NATURAL_8]
Generate a new random UUID v4 as a 16-byte array.
Contracts
new_v4_string: STRING
Generate a new random UUID v4 as a hyphenated string (36 characters).
Example: 550e8400-e29b-41d4-a716-446655440000
Contracts
new_v4_compact: STRING
Generate a new random UUID v4 without hyphens (32 characters).
Example: 550e8400e29b41d4a716446655440000
Contracts
UUID v7 (Timestamp)
UUID v7 embeds a Unix millisecond timestamp in the first 48 bits, making UUIDs sortable by creation time.
new_v7: ARRAY [NATURAL_8]
Generate a new timestamp-based UUID v7 as a 16-byte array.
Contracts
new_v7_string: STRING
Generate a new timestamp-based UUID v7 as a hyphenated string.
Example: 0190a926-3b00-7abc-8def-123456789abc
Contracts
new_v7_compact: STRING
Generate a new timestamp-based UUID v7 without hyphens.
Contracts
Formatting Features
to_string (a_uuid: ARRAY [NATURAL_8]): STRING
Convert UUID bytes to hyphenated string format.
Format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Contracts
to_compact_string (a_uuid: ARRAY [NATURAL_8]): STRING
Convert UUID bytes to string without hyphens.
Contracts
Parsing Features
from_string (a_string: STRING): ARRAY [NATURAL_8]
Parse a UUID string (with or without hyphens) to a 16-byte array.
Contracts
Validation Features
is_valid_uuid (a_string: STRING): BOOLEAN
Check if a string is a valid hyphenated UUID (36 characters with hyphens at positions 9, 14, 19, 24).
Contracts
is_valid_uuid_compact (a_string: STRING): BOOLEAN
Check if a string is a valid compact UUID (32 hexadecimal characters, no hyphens).
Contracts
Comparison Features
is_nil (a_uuid: ARRAY [NATURAL_8]): BOOLEAN
Check if the UUID is the nil UUID (all zeros).
Contracts
nil_uuid: ARRAY [NATURAL_8]
Return the nil UUID (all zeros) as a byte array.
Contracts
nil_uuid_string: STRING
The nil UUID as a constant string.
Version Detection
version (a_uuid: ARRAY [NATURAL_8]): INTEGER
Get the version number (0-15) from UUID bytes. Common values: 4 (random), 7 (timestamp).
Contracts
version_from_string (a_string: STRING): INTEGER
Get the version number from a UUID string.
Contracts
Constants
| Constant | Value | Description |
|---|---|---|
Hex_chars |
0123456789abcdef |
Hexadecimal characters for formatting |
Nil_uuid_string |
00000000-0000-0000-0000-000000000000 |
The nil UUID as string |