ludic/ns-uuid.html
2026-09-17 22:10:03 +00:00

28 lines
No EOL
4.5 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Uuid — Ludic</title>
<meta name="description" content="Universally-unique identifiers — stable IDs that don&#x27;t collide, generated locally with no central authority handing out numbers.">
<link rel="stylesheet" href="base.css">
<link rel="stylesheet" href="docs.css">
</head>
<body>
<header class="nav"><div class="wrap nav-in"><a class="brand" href="index.html"><span class="logo">L</span> Ludic</a><button class="nav-toggle" aria-label="Toggle menu" aria-expanded="false">☰</button><nav class="nav-links"><a href="index.html">Home</a><a href="api.html">API Reference</a><a class="nav-cta" href="https://git.workshopsoft.io/workshopsoft/ludic">Source ↗</a></nav></div></header>
<main class="wrap item">
<div class="crumbs"><a href="api.html">API Reference</a> <span>›</span> <span class="here">Uuid</span></div>
<div class="item-head"><span class="kind-badge kind-namespace">namespace</span><h1 id="top">Uuid</h1></div>
<p class="ns-blurb">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. <a href="uuid-new"><code>Uuid.new</code></a> makes a **v4** (random) UUID — 122 bits of entropy, effectively never colliding. <a href="uuid-new_v7"><code>Uuid.new_v7</code></a> 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 (<code>8-4-4-4-12</code>), the same shape you store, print, send, and compare — so there is no conversion at each boundary. Validate untrusted input with <a href="uuid-is_valid"><code>Uuid.is_valid</code></a> or normalise it with <a href="uuid-parse"><code>Uuid.parse</code></a>, and compare with <a href="uuid-equals"><code>Uuid.equals</code></a>, which ignores case.
**Determinism caveat.** v4 and the random tail of v7 come from the OS cryptographically-secure RNG (<a href="ns-Crypto"><code>Crypto</code></a>), 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.</p>
<div class="ns-methods"><a class="ns-method" href="uuid-new.html"><code class="nm-sig">Uuid.new() -&gt; string</code><span class="nm-tip">A new random (v4) UUID as a canonical 36-char string.</span></a><a class="ns-method" href="uuid-v4.html"><code class="nm-sig">Uuid.v4() -&gt; string</code><span class="nm-tip">Explicit alias for Uuid.new — a random (v4) UUID.</span></a><a class="ns-method" href="uuid-new_v7.html"><code class="nm-sig">Uuid.new_v7() -&gt; string</code><span class="nm-tip">A new time-ordered (v7) UUID; sorts by creation time.</span></a><a class="ns-method" href="uuid-v7.html"><code class="nm-sig">Uuid.v7() -&gt; string</code><span class="nm-tip">Explicit alias for Uuid.new_v7 — a time-ordered UUID.</span></a><a class="ns-method" href="uuid-parse.html"><code class="nm-sig">Uuid.parse(s) -&gt; string</code><span class="nm-tip">Normalise an untrusted string to a lowercase UUID, or the nil UUID.</span></a><a class="ns-method" href="uuid-is_valid.html"><code class="nm-sig">Uuid.is_valid(s) -&gt; bool</code><span class="nm-tip">Is s a well-formed UUID string?</span></a><a class="ns-method" href="uuid-to_text.html"><code class="nm-sig">Uuid.to_text(id) -&gt; string</code><span class="nm-tip">The canonical text form of a UUID.</span></a><a class="ns-method" href="uuid-equals.html"><code class="nm-sig">Uuid.equals(a, b) -&gt; bool</code><span class="nm-tip">Case-insensitive UUID equality.</span></a><a class="ns-method" href="uuid-nil.html"><code class="nm-sig">Uuid.nil() -&gt; string</code><span class="nm-tip">The all-zero UUID.</span></a></div>
<a class="back" href="api.html">← All symbols</a>
</main>
<script src="ludic-highlight.js"></script>
<script>Ludic.installCards(); Ludic.flashTarget();</script>
</body></html>