engine: seeded RNG helper, first tests

math/rand/v2 (Go 1.22+) replaces the old math/rand: PCG generator,
no global Seed(), and rand.New(rand.NewPCG(seed, 0)) gives an isolated
deterministic stream. Each randomness consumer (graph, thresholds,
education sampling) will get its own stream so levers vary independently.
Tests live next to the code as *_test.go; 'go test ./...' runs them all.
'for i := range 100' is Go 1.22 range-over-int.
This commit is contained in:
Justin Visser 2026-06-10 11:57:39 +02:00
parent d8125655e6
commit 33d40a18ea
2 changed files with 42 additions and 0 deletions

16
internal/engine/rng.go Normal file
View file

@ -0,0 +1,16 @@
// 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.
func newRand(seed uint64) *rand.Rand {
return rand.New(rand.NewPCG(seed, 0))
}