From 39abb1a43bb48639ad389df7d8cb57448c549917 Mon Sep 17 00:00:00 2001 From: clockwork-labs-bot Date: Sat, 21 Mar 2026 09:08:41 -0400 Subject: [PATCH] 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 --- .../00300-reducers/00400-reducer-context.md | 7 ++----- .../00300-reducers/00400-reducer-context.md | 7 ++----- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/docs/docs/00200-core-concepts/00200-functions/00300-reducers/00400-reducer-context.md b/docs/docs/00200-core-concepts/00200-functions/00300-reducers/00400-reducer-context.md index 0dbd82df8..4338f0083 100644 --- a/docs/docs/00200-core-concepts/00200-functions/00300-reducers/00400-reducer-context.md +++ b/docs/docs/00200-core-concepts/00200-functions/00300-reducers/00400-reducer-context.md @@ -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) | diff --git a/docs/versioned_docs/version-1.12.0/00200-core-concepts/00200-functions/00300-reducers/00400-reducer-context.md b/docs/versioned_docs/version-1.12.0/00200-core-concepts/00200-functions/00300-reducers/00400-reducer-context.md index 47c55b1cc..09bff7753 100644 --- a/docs/versioned_docs/version-1.12.0/00200-core-concepts/00200-functions/00300-reducers/00400-reducer-context.md +++ b/docs/versioned_docs/version-1.12.0/00200-core-concepts/00200-functions/00300-reducers/00400-reducer-context.md @@ -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) |