diff --git a/docs/docs/00200-core-concepts/00100-databases/00500-cheat-sheet.md b/docs/docs/00200-core-concepts/00100-databases/00500-cheat-sheet.md index 4a52f82ac51..91fe874d848 100644 --- a/docs/docs/00200-core-concepts/00100-databases/00500-cheat-sheet.md +++ b/docs/docs/00200-core-concepts/00100-databases/00500-cheat-sheet.md @@ -753,6 +753,7 @@ ctx.sender // Identity of caller ctx.connectionId // ConnectionId | undefined ctx.timestamp // Timestamp ctx.identity // Module's identity +ctx.random // Deterministic random generator ``` @@ -764,7 +765,7 @@ ctx.Sender // Identity of caller ctx.ConnectionId // ConnectionId? ctx.Timestamp // Timestamp ctx.Identity // Module's identity -ctx.Rng // Random number generator +ctx.Rng // Deterministic random generator ``` @@ -776,7 +777,7 @@ ctx.sender() // Identity of caller ctx.connection_id() // Option ctx.timestamp // Timestamp ctx.identity() // Module's identity -ctx.rng() // Random number generator +ctx.rng() // Deterministic random generator ``` @@ -788,7 +789,7 @@ ctx.sender() // Identity of caller (Identity type) ctx.connection_id // std::optional ctx.timestamp // Timestamp of current transaction (Timestamp type) ctx.identity() // Module's own identity (Identity type) -ctx.rng() // Random number generator (for seeded randomness) +ctx.rng() // Deterministic random generator ``` diff --git a/skills/concepts/SKILL.md b/skills/concepts/SKILL.md index 402a1a8ff18..1b73ae2d3e3 100644 --- a/skills/concepts/SKILL.md +++ b/skills/concepts/SKILL.md @@ -20,7 +20,7 @@ SpacetimeDB is a relational database that is also a server. It lets you upload a ## Critical Rules 1. **Reducers are transactional.** They do not return data to callers. Use subscriptions to read data. -2. **Reducers must be deterministic.** No filesystem, network, timers, or random. All state must come from tables. +2. **Reducers must be deterministic.** No filesystem, network, timers, wall-clock time, or ambient randomness. Use `ReducerContext` APIs such as `ctx.timestamp` / `ctx.Timestamp` and the language-specific deterministic RNG instead. 3. **Read data via tables/subscriptions**, not reducer return values. Clients get data through subscribed queries. 4. **Auto-increment IDs are not sequential.** Gaps are normal, do not use for ordering. Use timestamps or explicit sequence columns. 5. **`ctx.sender` is the authenticated principal.** Never trust identity passed as arguments.