/p/moul/x/daily/markov/v0
gno.land/p/moul/x/daily/markov/v0
Deterministic Markov-chain text generator — a port of Go's canonical example
"Generating arbitrary text: a Markov chain algorithm"
with math/rand replaced by a caller-supplied seed.
A Chain maps every two-word prefix to the list of words observed to follow
it (duplicates kept, so frequency biases the walk), storing that map in a
persistent avl.Tree. Build folds text into the chain; Generate walks it
from the start prefix, picking one suffix per step from a small LCG seeded by
the uint64 you pass — so generation is pure and replayable, and the caller
decides where entropy comes from (on-chain, the block height). No chain imports,
no ambient state.
1import "gno.land/p/moul/x/daily/markov/v0"
2
3c := markov.New()
4c.Build("it was the best of times it was the worst of times") // fold in a corpus
5words := c.Generate(40, seed) // walk it, seeded
6c.Stats() // (totalWords, prefixCount)
7c.Iterate(func(prefix string, suffixes []string) bool { ... }) // inspect the map
Live demo: r/moul/x/daily/markovdemo
· render it at /r/moul/x/daily/markovdemo/v0.
Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.
Dependency graph:

🧪 Highly experimental — potentially vibe-coded. Not audited; may break, change, or be removed at any time. Do not use with anything of value. Full disclaimer: DISCLAIMER.