Move a table's rows, links and pins into internal/rows, and walk every path through one per-step function, so Fake refuses a level carrying a repeat
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
// Package drawstate holds a generator's seeded randomness and its {seq()} counters.
|
||||
package drawstate
|
||||
|
||||
import "math/rand/v2"
|
||||
import (
|
||||
"math/rand/v2"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// State is one generator's draw state, kept across its renders.
|
||||
type State struct {
|
||||
@@ -18,6 +21,12 @@ func (s *State) IntN(n int) int { return s.rand.IntN(n) }
|
||||
|
||||
func (s *State) Float64() float64 { return s.rand.Float64() }
|
||||
|
||||
// Weighted draws an index into cum, a running sum of positive weights, with odds by weight.
|
||||
func (s *State) Weighted(cum []float64) int {
|
||||
x := s.Float64() * cum[len(cum)-1]
|
||||
return min(sort.Search(len(cum), func(i int) bool { return cum[i] > x }), len(cum)-1) // x can round up to the total
|
||||
}
|
||||
|
||||
// Seq advances the counter {seq(key)} reads, or {seq()} for an empty key, and returns it.
|
||||
func (s *State) Seq(key string) uint64 {
|
||||
s.counters[key]++
|
||||
|
||||
Reference in New Issue
Block a user