Skip to main content

Interface: WorkflowRandomStream

workflow.WorkflowRandomStream

A deterministic PRNG stream scoped to the current Workflow execution.

Workflow code already gets a deterministic default stream through Math.random(). This interface exposes additional named streams that are derived from the workflow seed without consuming that default stream. Repeated calls to getRandomStream with the same name refer to the same logical stream state for the current workflow execution, and that state is preserved across activations.

The primary use case is workflow plugins and interceptors that need private, replay-stable entropy without perturbing user workflow randomness.

This API may be removed or changed in the future.

Methods

fill

fill(bytes): Uint8Array

Fill a byte array deterministically from this stream.

Parameters

NameType
bytesUint8Array

Returns

Uint8Array


random

random(): number

Draw the next deterministic pseudo-random number from this stream.

This is equivalent to Math.random(), but isolated from the workflow's main random stream and from other named streams.

Returns

number


uuid4

uuid4(): string

Generate a deterministic UUIDv4 backed by this stream.

Returns

string


with

with<T>(fn): T

Run fn with scoped workflow-random helpers such as Math.random() and uuid4() routed through this stream.

This is the scoped override API for workflow random streams. It is intended for bounded plugin/interceptor code that needs existing calls to Math.random() or uuid4() to use this stream without perturbing the workflow's default random sequence or any other named stream.

The override follows async continuations started by fn. Workflow interceptor next(...) continuations restore the downstream workflow random scope before entering the rest of the interceptor chain or workflow code, so a temporary plugin scope does not leak downstream unless that downstream code explicitly establishes its own scope.

Prefer explicit stream.random() / stream.uuid4() calls when that is practical. Use stream.with(...) when a temporary scoped override is the better fit, or when you want to keep the stream instance in module scope and reuse it directly.

Type parameters

Name
T

Parameters

NameType
fn() => T

Returns

T