home ~ projects ~ socials

Generate A Markov Chain String Of Text In Rust

Using markov

There's a few Markov chain generator crates. I'm using the one that's simply called markov1. It's simple and does that I need:

---
[dependencies]
markov = "1.1.0"
---

use markov::Chain;

fn main() {
  let mut chain = Chain::new();
  let texts = vec![
    "I like cats and I like dogs.",
    "This is a thing that I am into.",
    "Jazz is one of my favorite types of music.",
    "Listening to music is my favorite.",
  ];
  texts.iter().for_each(|text| {
    chain.feed_str(text);
  });
  println!("{}", chain.generate_str());
}
Output:
I like cats and I am into.
-- end of line --

Footnotes

1 ⤴