{"id":28302631,"url":"https://github.com/taylordotfish/markov-generator","last_synced_at":"2026-03-05T14:32:22.887Z","repository":{"id":62445024,"uuid":"528351197","full_name":"taylordotfish/markov-generator","owner":"taylordotfish","description":"Highly customizable Rust library for building Markov chains and generating random data from them","archived":false,"fork":false,"pushed_at":"2024-12-14T02:10:37.000Z","size":271,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-02-13T08:51:42.631Z","etag":null,"topics":["markov","markov-chain","markov-text","random","rust","serialization","text-generation"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/taylordotfish.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-24T09:22:21.000Z","updated_at":"2024-12-14T02:13:12.000Z","dependencies_parsed_at":"2024-12-07T07:24:21.336Z","dependency_job_id":"f2769c68-1763-4209-8224-81e35255c00f","html_url":"https://github.com/taylordotfish/markov-generator","commit_stats":{"total_commits":8,"total_committers":1,"mean_commits":8.0,"dds":0.0,"last_synced_commit":"779ba0058289a144a4cc798b09cfd4afb966e921"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/taylordotfish/markov-generator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taylordotfish%2Fmarkov-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taylordotfish%2Fmarkov-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taylordotfish%2Fmarkov-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taylordotfish%2Fmarkov-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/taylordotfish","download_url":"https://codeload.github.com/taylordotfish/markov-generator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taylordotfish%2Fmarkov-generator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30130438,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-05T12:40:50.676Z","status":"ssl_error","status_checked_at":"2026-03-05T12:39:32.209Z","response_time":93,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["markov","markov-chain","markov-text","random","rust","serialization","text-generation"],"created_at":"2025-05-23T21:11:57.996Z","updated_at":"2026-03-05T14:32:22.875Z","avatar_url":"https://github.com/taylordotfish.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"markov-generator\n================\n\nA highly customizable Rust library for building [Markov chains] and\ngenerating random sequences from them.\n\n[Markov chains]: https://en.wikipedia.org/wiki/Markov_chain\n\n[`Chain`] implements [Serde]’s [`Serialize`] and [`Deserialize`] traits, so\nyou can reuse chains without having to regenerate them every time (which\ncan be a lengthy process).\n\nExample\n-------\n\n```rust\nuse markov_generator::{AddEdges, HashChain};\n\nconst DEPTH: usize = 6;\n// Maps each sequence of 6 items to a list of possible next items.\n// `HashChain` uses hash maps internally; b-trees can also be used.\nlet mut chain = HashChain::new(DEPTH);\n\n// In this case, corpus.txt contains one paragraph per line.\nlet file = File::open(\"examples/corpus.txt\")?;\nlet mut reader = BufReader::new(file);\nlet mut line = String::new();\n// The previous `DEPTH` characters before `line`.\nlet mut prev = Vec::\u003cchar\u003e::new();\n\nwhile let Ok(1..) = reader.read_line(\u0026mut line) {\n    // `Both` means that the generated random output could start with the\n    // beginning of `line` or end after the end of `line`.\n    chain.add_all(line.chars(), AddEdges::Both);\n\n    // This makes sure there's a chance that the end of the previous line\n    // could be followed by the start of the current line when generating\n    // random output.\n    chain.add_all(\n        prev.iter().copied().chain(line.chars().take(DEPTH)),\n        AddEdges::Neither,\n    );\n\n    if let Some((n, (i, _c))) =\n        line.char_indices().rev().enumerate().take(DEPTH).last()\n    {\n        // Keep only the most recent `DEPTH` characters.\n        prev.drain(0..prev.len().saturating_sub(DEPTH - n - 1));\n        prev.extend(line[i..].chars());\n    }\n    line.clear();\n}\n\n// Generate and print random Markov data.\nlet mut stdout = BufWriter::new(io::stdout().lock());\nlet mut prev_newline = false;\nfor \u0026c in chain.generate() {\n    if prev_newline {\n        writeln!(stdout)?;\n    }\n    prev_newline = c == '\\n';\n    write!(stdout, \"{c}\")?;\n}\nstdout.flush()?;\n```\n\nCrate features\n--------------\n\n* `std` (default: enabled): Use [`std`]. If disabled, this crate is marked\n  `no_std`.\n* `serde` (default: enabled): Implement [Serde]’s [`Serialize`] and\n  [`Deserialize`] traits for [`Chain`].\n\n[`Chain`]: https://docs.rs/markov-generator/0.2/markov_generator/struct.Chain.html\n[Serde]: https://docs.rs/serde/1/serde/\n[`Serialize`]: https://docs.rs/serde/1/serde/trait.Serialize.html\n[`Deserialize`]: https://docs.rs/serde/1/serde/trait.Deserialize.html\n[`std`]: https://doc.rust-lang.org/stable/std/\n\nDocumentation\n-------------\n\n[Documentation is available on docs.rs.](https://docs.rs/markov-generator)\n\nLicense\n-------\n\nmarkov-generator is licensed under version 3 of the GNU General Public License,\nor (at your option) any later version. See [LICENSE](LICENSE).\n\nContributing\n------------\n\nBy contributing to markov-generator, you agree that your contribution may be\nused according to the terms of markov-generator’s license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaylordotfish%2Fmarkov-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftaylordotfish%2Fmarkov-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaylordotfish%2Fmarkov-generator/lists"}