/** * @module prng * Seeded pseudo-random number generation and per-field seed derivation. * * ## Why per-field seeding? * * A sequential PRNG shifts every downstream value when a field is added or * removed from a schema. Per-field seeding avoids this: each field gets its * own seed derived from `hash(worldSeed + subjectId + fieldPath)`, so adding * a new field never affects the values of existing fields. * * ## Algorithms * - **PRNG**: SFC32 — passes all standard statistical tests, 128-bit state, period ~3.4×10³⁸. * - **Hash**: FNV-1a 32-bit — fast, low collision rate for short strings. * * ## B97-R14 — class shape with prototype methods * * `createPrng(seed)` returns an `SFC32Prng` instance whose methods live on * `SFC32Prng.prototype` (not as per-instance closure-object properties). The * byte-identical SFC32 state machine is preserved — the refactor only flips * the allocation shape from closure-object to class. */ import type { Prng } from "./types.js"; /** FNV-1a 32-bit hash over a UTF-16 string, returns an unsigned 32-bit integer. */ export declare function fnv1a(str: string): number; /** One step of splitmix32 — avalanches all 32 bits. Used for integer seed mixing. */ export declare function splitmix32(s: number): number; /** * B97-R14 — class-shaped SFC32 PRNG with all methods on the prototype. * * Holds the SFC32 state (4 unsigned 32-bit integers) as own properties. The * methods are class-syntax (so they live on `SFC32Prng.prototype`), which * makes `new SFC32Prng(seed)` allocate just the four state slots + the * `seed` slot — no per-instance closure properties. * * Byte-identity with the legacy closure-object factory is preserved: the * SFC32 step (`random()`), the `seedToSfc32` initialisation, the `fork(key)` * hash derivation, and the closed-form `pickZipf` / `logUniform` / * `geometric` formulas are unchanged. */ export declare class SFC32Prng implements Prng { readonly seed: number; private _a; private _b; private _c; private _d; constructor(seed: number); random(): number; int(min: number, max: number): number; pick(items: readonly [T, ...T[]]): T; logUniform(min: number, max: number): number; geometric(p: number): number; pickZipf(items: readonly T[], s: number): T; shuffle(items: readonly T[]): T[]; sample(items: readonly T[], count: number): T[]; fork(key: string): Prng; bytes(n: number): Uint8Array; } /** * Create a seeded PRNG. * * @param seed - Any 32-bit integer. The same seed always produces the same sequence. */ export declare function createPrng(seed: number): Prng; /** * Derive a deterministic field-level seed from three stable inputs. * * Used to give each field its own independent PRNG so that schema changes * (adding / removing fields) do not affect unrelated fields. * * @param worldSeed - The world's master seed. * @param subjectId - The subject instance's unique ID (e.g. `'person#3'`). * @param fieldPath - Dot-separated field path (e.g. `'address.street'`). */ export declare function fieldSeed(worldSeed: number, subjectId: string, fieldPath: string): number; //# sourceMappingURL=prng.d.ts.map