Files
aevolution/docs/adr/0007-prng.md
T
2026-10-08 12:08:53 -04:00

1.5 KiB

[Reviewed]

ADR-0007: Explicit deterministic random streams

Status

SplitMix64 and unbiased ternary mapping adopted for synthetic proof; production stream strategy deferred.

Context

A seed is insufficient when draw order or distribution mapping is unspecified.

Decision

Serialize per-entity u64 state. next adds 0x9e3779b97f4a7c15 modulo2^64; z=(z xor(z>>30))*0xbf58476d1ce4e5b9; z=(z xor(z>>27))0x94d049bb133111eb; return z xor(z>>31). Seed each entity from next() of seed XOR (id0xd1b54a32d192ed03 modulo2^64). For ternary, reject output zero, then modulo3: the remaining 2^64-1 outputs divide evenly into three bins. Two accepted draws per tick drive x/y; rejected draws still advance state.

Alternatives Considered

PCG/xoshiro/counter-based generators have different state/stream tradeoffs. Standard engines with unspecified distributions do not define our byte contract.

Benefits

Auditable algorithm, compact entity-local state, reference vectors.

Costs

Explicit draw-order versioning and bounded-mapping review.

Risks

Nearby seeds do not establish statistical stream independence at planetary scale.

Consequences

Golden-test seed expansion/restoration/order. Later biology requires named subsystem streams and distribution evidence. Never use this RNG for authentication, secrets or anti-replay nonces. Reference. Initial draft's raw modulo mapping was corrected before implementation to avoid bias; the frozen fixture and kernel use rejection.