Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

markov package

Overview

Package markov ports the canonical Go example "Generating arbitrary text: a Markov chain algorithm" (https://go.dev/doc/codewalk/markov/) to a gno.land realm.

The original reads words from an io.Reader, builds a map from each two-word prefix to the list of words that followed it, then walks that chain picking random suffixes to babble new text. Here the corpus lives on-chain: Feed appends words to a persistent avl.Tree-backed chain, and Generate walks it. The only change needed for on-chain determinism is the source of randomness: instead of math/rand we seed a small LCG with runtime.ChainHeight(), so Generate is a pure, reproducible query that still varies block to block.

Feed is a crossing function (takes `cur realm` first) because it mutates on-chain state; Generate and Render are read-only.

Functions

Feed

func Feed(cur realm, text string) string

Feed appends text to the on-chain corpus, extending the Markov chain. Any caller may enrich the corpus — this is the open-membership demo model.

Param

Command

# WARNING: This command is running in an INSECURE mode.
# It is strongly recommended to use a hardware device for signing
# and avoid trusting any computer connected to the internet,
# as your private keys could be exposed.

gnokey maketx call -pkgpath "gno.land/r/g12cs4cehujpffpjpywmkqj43m6u5ya53nj69sjz/markov" -func "Feed" -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -chainid "topaz-1" -remote "https://rpc.topaz.testnets.gno.land" ADDRESSgnokey query -remote "https://rpc.topaz.testnets.gno.land" auth/accounts/ADDRESS
gnokey maketx call -pkgpath "gno.land/r/g12cs4cehujpffpjpywmkqj43m6u5ya53nj69sjz/markov" -func "Feed" -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -broadcast=false ADDRESS > call.tx
gnokey sign -tx-path call.tx -chainid "topaz-1" -account-number ACCOUNTNUMBER -account-sequence SEQUENCENUMBER ADDRESS
gnokey broadcast -remote "https://rpc.topaz.testnets.gno.land" call.tx
  

Generate

func Generate(nWords int) string

Generate babbles up to nWords of Markov text from the current corpus, seeded deterministically by the chain height. Read-only.

Param

Command

gnokey query vm/qeval -remote "https://rpc.topaz.testnets.gno.land" -data "gno.land/r/g12cs4cehujpffpjpywmkqj43m6u5ya53nj69sjz/markov.Generate()"

Result

Render

func Render(path string) string

Render shows a freshly generated sample plus corpus stats. The path may carry a word count, e.g. Render("/60").

Param

Command

gnokey query vm/qeval -remote "https://rpc.topaz.testnets.gno.land" -data "gno.land/r/g12cs4cehujpffpjpywmkqj43m6u5ya53nj69sjz/markov.Render()"

Result

Stats

func Stats() (int, int)

Stats returns (totalWords, prefixCount) for the current corpus.

Command

gnokey query vm/qeval -remote "https://rpc.topaz.testnets.gno.land" -data "gno.land/r/g12cs4cehujpffpjpywmkqj43m6u5ya53nj69sjz/markov.Stats()"

Result