API Reference › Uuid
namespace

Uuid

Universally-unique identifiers — stable IDs that don't collide, generated locally with no central authority handing out numbers. Reach for a UUID whenever something needs an identity that survives being saved, shared, or sent over a network: players and sessions in multiplayer, user-created content (levels, items, mods) that has to merge cleanly across installs, or a per-install / per-run ID for analytics and bug reports. Two versions are provided. Uuid.new makes a **v4** (random) UUID — 122 bits of entropy, effectively never colliding. Uuid.new_v7 makes a **v7** (time-ordered) UUID whose leading bits are a millisecond timestamp, so a batch of v7 IDs sorts by creation time — friendly to database indexes and append logs. Both set the RFC 4122 version and variant bits correctly. A UUID is represented as its canonical lowercase 36-character text form (8-4-4-4-12), the same shape you store, print, send, and compare — so there is no conversion at each boundary. Validate untrusted input with Uuid.is_valid or normalise it with Uuid.parse, and compare with Uuid.equals, which ignores case. **Determinism caveat.** v4 and the random tail of v7 come from the OS cryptographically-secure RNG (Crypto), which is non-deterministic by design. Minting a UUID inside the lockstep simulation will desync replays and networked peers — generate IDs at the edges (on connect, on save, on spawn-from-input), never per tick in reproducible gameplay code.

Uuid.new() -> stringA new random (v4) UUID as a canonical 36-char string.Uuid.v4() -> stringExplicit alias for Uuid.new — a random (v4) UUID.Uuid.new_v7() -> stringA new time-ordered (v7) UUID; sorts by creation time.Uuid.v7() -> stringExplicit alias for Uuid.new_v7 — a time-ordered UUID.Uuid.parse(s) -> stringNormalise an untrusted string to a lowercase UUID, or the nil UUID.Uuid.is_valid(s) -> boolIs s a well-formed UUID string?Uuid.to_text(id) -> stringThe canonical text form of a UUID.Uuid.equals(a, b) -> boolCase-insensitive UUID equality.Uuid.nil() -> stringThe all-zero UUID.
← All symbols