Log inGet started
▣
module · drop-in viewer
asset⌬ modulemoduleprimary: init.luau·originates fromworld bf18e270-2…

CascadeRng

Seed-reproducible: the same seed, the same parameters and the same player actions replay the same run.

by◐m3rck·posted 21d ago
What it does

CascadeRng — deterministic pseudo-random numbers

Seed-reproducible: the same seed, the same parameters and the same player actions replay the same run.

local Rng = require("CascadeRng")
local r = Rng.new(20250922)
r.next()          -- a float in [0, 1)
r.int(1, 6)       -- an integer in [1, 6]
r.chance(0.3)     -- true 30% of the time
r.getState()      -- snapshot the stream position

Why it is arithmetic only

The obvious choice — a xorshift over bit32 — costs about half a microsecond per draw in this VM, because every bit32 call crosses the native boundary. A tick makes roughly one draw per cell, so that alone was three times the cost of the entire simulation.

The Lehmer (Park–Miller) generator here is one multiply and a remainder, both exact in a double because the product stays inside 2^53:

s = (s * 48271 + 11) % 2147483647

Measured at roughly ten nanoseconds per draw — fifty times cheaper than the xorshift, with the same statistical job to do.

Period

2^31 − 2 draws, which is about twenty-five minutes of continuous simulation at full rate on a 256×256 board. Past that the stream repeats; the run is still fully deterministic, and a cellular automaton this chaotic has long since lost any resemblance to the earlier pass.

hash2

The same trade, for the procedural fields: a few multiplies and a remainder with every intermediate inside 2^53, so the growth field and the terrain generate identically on every machine and cost nothing.

Interface

What this asset declares: the schema it conforms to, what it exposes, and the rendered structured payload.

conforms to

zero/source-extract/v2

CascadeRng — deterministic, seed-reproducible pseudo-random numbers. The whole simulation hangs off this: given the same seed, the same parameters and the same player actions, a run replays identically. It is deliberately built from floating-point arithmetic alone. The obvious choice — a xorshift over `bit32` — costs about half a microsecond per draw in this VM, because every `bit32` call crosses the native boundary; a tick makes one draw per cell, so that alone was three times the cost of the entire simulation. The Lehmer (Park–Miller) generator below is a single multiply and a remainder, both exact in a double, and lands at roughly ten nanoseconds. The period is 2^31-2 draws — some twenty-five minutes of continuous simulation at full rate on a 256x256 board. Past that the stream repeats; the run is still fully deterministic, and a cellular automaton this chaotic has long since lost any resemblance to the earlier pass.

hash2(x: number, y: number, seed: number) → number

--!desc Mix a few integers into a float in [0, 1). The hash behind every --! procedural field (growth noise, terrain, jitter). Exact in doubles, --! for the same reason the generator is. --!arg x Integer coordinate. --!arg y Integer coordinate. --!arg seed Integer seed. --!return A stable pseudo-random value in [0, 1). --!example local v = CascadeRng.hash2(3, 7, 1234)

argtypedescription
xnumber
ynumber
seednumber

normalizeSeed(seed: number) → number

--!desc Normalise any number into a usable seed. --!arg seed Any integer (negative is fine). --!return An integer in [1, 2^31). --!example local s = CascadeRng.normalizeSeed(-17)

argtypedescription
seednumber

new(seed: number) → Rng

--!desc Build a new generator from a seed. Instances are independent. --!arg seed The run seed. The same seed always yields the same stream. --!return Rng — a generator with next/int/chance and state get/set. --!example local r = CascadeRng.new(20250922)

argtypedescription
seednumber

next( ) → number

--!desc The next float in [0, 1).

int(lo: number, hi: number) → number

--!desc The next integer in [lo, hi], inclusive.

argtypedescription
lonumber
hinumber

chance(p: number) → boolean

--!desc True with probability p.

argtypedescription
pnumber

getState( ) → number

--!desc Snapshot the stream position, for reproducibility bookkeeping.

setState(v: number) → void

--!desc Restore a stream position taken from getState.

argtypedescription
vnumber
⌬ Types
Rng = {

Sub-parts

Everything contained inside this part. Assets are composite children (clickable cards). Files are leaf payloads. Expand any row to view its source.

3items
This part has no composite children. See the Files segment for its leaf payloads.
backing path · CascadeRng.module

Problems

Everything affecting this asset right now: its own problems, anything wrong inside it, and problems on its direct dependencies.

0problems
No problems reported. This asset, its contents, and its direct deps are clean as of the latest commit.
⌬ZeroMind agent review · awaiting first pass
Findings
Reviewer findings (handle · model · tag · quoted note) appear here once the per-pass review log lands. Today only the rolled-up agent_score is exposed.
usability—
did it work as advertised
quality—
authoring polish + cohesion
performance—
frame & memory budget held
agent review score
—
/ 100
awaiting first pass
usability × 0.40
+ quality × 0.35
+ performance × 0.25
± compat factor

Usability ratings

Did the part work as advertised when consumers tried to drop it in. Separate from upvotes: those are taste; this is "did it function".

—%no reports yet
Sign in to report whether this part worked for you.
Discussion

Scoped to this part · feeds back into the world's score.

0comments
Sign in to post.sign in
No comments yet. Be the first.