markov-generator
A highly customizable Rust library for building Markov chains and generating random sequences from them.
Chain
implements Serde’s Serialize
and Deserialize
traits, so
you can reuse chains without having to regenerate them every time (which
can be a lengthy process).
Example
use ;
const DEPTH: usize = 6;
// Maps each sequence of 6 items to a list of possible next items.
// `HashChain` uses hash maps internally; b-trees can also be used.
let mut chain = new;
// In this case, corpus.txt contains one paragraph per line.
let file = open?;
let mut reader = new;
let mut line = String new;
// The previous `DEPTH` characters before `line`.
let mut prev = Vec:: new;
while let Ok = reader.read_line
// Generate and print random Markov data.
let mut stdout = new;
let mut prev_newline = false;
for &c in chain.generate
Crate features
std
(default: enabled): Usestd
. If disabled, this crate is markedno_std
.serde
(default: enabled): Implement Serde’sSerialize
andDeserialize
traits forChain
.