[−][src]Crate gmarkov_lib
A library that provides Markov chain data structures.
The MarkovChain
structure allows you to feed in several sequences of items
and get out a sequence that looks very similar, but is randomly generated.
This is the library to my CLI app gmarkov
.
Example
extern crate gmarkov_lib; use std::fs::File; use std::io::{Result, BufRead, BufReader}; use gmarkov_lib::MarkovChain; fn main() -> Result<()> { let mut chain = MarkovChain::with_order::<char>(2); let reader = BufReader::new(File::open("examples/dictionary_sample.txt")?); for line in reader.lines() { chain.feed(line?.chars()); } println!("New word: {}", chain.into_iter().collect::<String>()); Ok(()) }
The short program above will create a Markov chain of order 2, then feed it
100 random words from the dictionary (in examples/dictionary_sample.txt
), then print out
one new random word.
Structs
MarkovChain | The Markov Chain data structure |
MarkovIterator | An iterator that produces the values of a Markov chain |
Traits
ChainItem | Trait alias for |