docs: Fix incorrect Math.random() note in reducer context (#4667)

Per Joshua: the note about `Math.random()` in the reducer context docs
is out of date and incorrect. TypeScript modules should use `ctx.random`
instead.

**Changes:**
- Remove `Math.random()` from the warning about non-deterministic RNGs
(it was listed alongside C#'s `Random` as something to avoid)
- Replace the incorrect `:::note` block with a proper table row
documenting `ctx.random` in the TypeScript context properties reference
- Same fixes applied to versioned docs (v1.12.0)

Co-authored-by: clockwork-labs-bot <clockwork-labs-bot@users.noreply.github.com>
This commit is contained in:
clockwork-labs-bot
2026-03-21 09:08:41 -04:00
committed by GitHub
parent 30cc7e0758
commit 39abb1a43b
2 changed files with 4 additions and 10 deletions
@@ -269,7 +269,7 @@ The timestamp indicates when the reducer was invoked. This value is consistent t
The context provides access to a random number generator that is deterministic and reproducible. This ensures that reducer execution is consistent across all nodes in a distributed system.
:::warning
Never use external random number generators (like `Math.random()` in TypeScript or `Random` in C# without using the context). These are non-deterministic and will cause different nodes to produce different results, breaking consensus.
Never use external random number generators (like `Random` in C# without using the context). These are non-deterministic and will cause different nodes to produce different results, breaking consensus.
:::
## Module Identity
@@ -409,10 +409,7 @@ SPACETIMEDB_REDUCER(send_reminder, ReducerContext ctx, ScheduledTask task) {
| `senderAuth` | `AuthCtx` | Authorization context for the caller (includes JWT claims and internal call detection) |
| `connectionId` | `ConnectionId \| undefined`| Connection ID of the caller, if available |
| `timestamp` | `Timestamp` | Time when the reducer was invoked |
:::note
TypeScript uses `Math.random()` for random number generation, which is automatically seeded deterministically by SpacetimeDB.
:::
| `random` | `Random` | Random number generator (deterministic, seeded by SpacetimeDB) |
</TabItem>
<TabItem value="csharp" label="C#">
@@ -204,7 +204,7 @@ The timestamp indicates when the reducer was invoked. This value is consistent t
The context provides access to a random number generator that is deterministic and reproducible. This ensures that reducer execution is consistent across all nodes in a distributed system.
:::warning
Never use external random number generators (like `Math.random()` in TypeScript or `Random` in C# without using the context). These are non-deterministic and will cause different nodes to produce different results, breaking consensus.
Never use external random number generators (like `Random` in C# without using the context). These are non-deterministic and will cause different nodes to produce different results, breaking consensus.
:::
## Module Identity
@@ -313,10 +313,7 @@ fn send_reminder(ctx: &ReducerContext, task: ScheduledTask) {
| `senderAuth` | `AuthCtx` | Authorization context for the caller (includes JWT claims and internal call detection) |
| `connectionId` | `ConnectionId \| undefined`| Connection ID of the caller, if available |
| `timestamp` | `Timestamp` | Time when the reducer was invoked |
:::note
TypeScript uses `Math.random()` for random number generation, which is automatically seeded deterministically by SpacetimeDB.
:::
| `random` | `Random` | Random number generator (deterministic, seeded by SpacetimeDB) |
</TabItem>
<TabItem value="csharp" label="C#">