markov_rs

markov_rs Crates.io docs.rs Crates.io

A simple and fast Markov chain generator in Rust.

By using the Walker's Alias Method, a weighted random sampling algorithm, the model can generate elements very quickly. The benchmark for this crate and the Markov chain using the Cumulative Sum Method is as follows.

| Algorithm | Building model | Generation | | :-------------------: | :------------: | :--------: | | Walker's Alias Method | 117.15 ms | 9.2078 ms | | Cumulative Sum Method | 8.3087 ms | 168.02 ms |

For details about the Walker's Alias Method, see ichi-h / weighted_rand.

Usage

Add this to your Cargo.toml:

toml [dependencies] markov_rs = "0.1"

Example

```rust use markov_rs::MarkovChain;

fn main() { let text = vec![ "I", "think", "that", "that", "that", "that", "that", "boy", "wrote", "is", "wrong", ];

let mut model = MarkovChain::from(&text);

for _ in 0..20 {
    print!("{} ", model.next());
}

} ```

Planned

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.