persona_db/engines/rng.py
Deterministic seeded RNG wrapper for all PersonaDB engines.
Provides SeededRNG — a thin wrapper around numpy.random.Generator with
reproducible fork semantics. Every engine MUST use SeededRNG instead of
the plain random module so that simulations are fully reproducible.
Ownership: Agent 2. Sibling agents import SeededRNG; never edit this file.
:::info Fonte
Módulo persona_db.engines.rng — 133 linhas · 1 classe(s) · 2 função(ões) pública(s). Ver no GitHub
:::
Classes
class SeededRNG
Deterministic RNG wrapping a numpy Generator.
Two SeededRNG instances seeded with the same parameters produce identical sequences regardless of global numpy state.
__init__()
def __init__(self, master_seed: int | None=None) -> None
fork()
def fork(self, persona_id: str, domain: str, salt: str='') -> SeededRNG
Return a new SeededRNG derived deterministically from this one.
seed_int = int.from_bytes(blake2b(master|persona|domain|salt)[:8], 'big') so identical (seed, persona_id, domain) always yield identical sequences while sibling personalities stay decorrelated.
bernoulli()
def bernoulli(self, p: float) -> bool
choice()
def choice(self, options: Sequence[Any], weights: Sequence[float] | None=None) -> Any
beta_sample()
def beta_sample(self, alpha: float, beta: float) -> float
normal_clipped()
def normal_clipped(self, mu: float, sigma: float, low: float, high: float) -> float
uniform()
def uniform(self, low: float, high: float) -> float
dirichlet()
def dirichlet(self, alphas: Sequence[float]) -> np.ndarray
integer()
def integer(self, low: int, high: int) -> int
Inclusive random integer in [low, high].
normal()
def normal(self, mu: float, sigma: float) -> float
poisson()
def poisson(self, lam: float) -> int
log_normal()
def log_normal(self, mu: float, sigma: float) -> float
rng()
@property
def rng(self) -> np.random.Generator
Funções
new_rng()
def new_rng(seed: int | None=None) -> SeededRNG
Factory shortcut.
register_seed()
def register_seed(persona_id: str, info: dict) -> None
Append a JSON record to persona_db/data/rng_log.jsonl.
The data directory is created if missing. Write failures are silently ignored so seeding/logging never breaks a simulation run.