spreadlab/internal/engine/rng.go
Justin Visser c3f65a4029 docs engine: state the RNG design decision in rng.go
rng.go is a construction point, not an abstraction wall; components
take *rand.Rand directly (idiomatic Go dependency injection) and only
RunScenario creates streams, from config seeds. Decided 2026-06-10
over the alternatives (interface wall, folding newRand into
scenario.go).
2026-06-10 13:01:39 +02:00

21 lines
996 B
Go

// Package engine implements the agent-based spread model: build a social
// network, run an independent cascade over it, and measure the effect of
// education strategies. It is pure: no I/O, no web dependencies, and all
// randomness flows from seeds in the config, so identical inputs always
// produce identical runs.
package engine
import "math/rand/v2"
// newRand returns a deterministic random stream for the given seed. The
// engine never touches global random state; every source of randomness
// (graph build, edge thresholds, education sampling) gets its own seeded
// stream so each can be varied independently.
//
// This file is deliberately NOT a wall around math/rand/v2: components
// take *rand.Rand parameters directly, the idiomatic Go shape. What is
// centralised here is construction; RunScenario is the only caller, so
// "all randomness flows from config seeds" is enforced by structure.
func newRand(seed uint64) *rand.Rand {
return rand.New(rand.NewPCG(seed, 0))
}