Move the seeded randomness and the {seq()} counters into internal/drawstate

This commit is contained in:
2026-10-05 11:43:45 +02:00
committed by Lillem4n
parent 4a680f03b3
commit 2d9c315e75
14 changed files with 107 additions and 76 deletions
+22
View File
@@ -0,0 +1,22 @@
// Package drawstate holds what a generator draws through: the seeded randomness and the
// {seq()} counters.
package drawstate
import "math/rand/v2"
// State is one generator's draw state, kept across its renders.
type State struct {
*rand.Rand
counters map[string]uint64
}
// New builds the state a seed reproduces.
func New(seed uint64) *State {
return &State{Rand: rand.New(rand.NewPCG(seed, seed^0x9e3779b97f4a7c15)), counters: map[string]uint64{}}
}
// Next advances the counter key names, the one {seq()} or {seq(key)} reads, and returns it.
func (s *State) Next(key string) uint64 {
s.counters[key]++
return s.counters[key]
}