Removed dependency on wordlist

This commit is contained in:
Joshua Barretto 2025-04-21 01:04:12 +01:00
parent 1c1f28007c
commit 40f159df1c

View file

@ -26,9 +26,6 @@ pub struct Args {
#[tokio::main]
async fn main() {
println!("Starting...");
let corpus = include_str!("/usr/share/dict/words")
.split_whitespace()
.collect::<Vec<_>>();
let mut freq = HashMap::<String, HashMap<String, usize>>::default();
include_str!("../wap.txt")
@ -69,12 +66,15 @@ async fn main() {
}
let mut rng = &mut ChaCha8Rng::from_seed(seed);
fn choose_word<'a, 'b>(corpus: &'b [&'b str], rng: &'a mut ChaCha8Rng) -> &'b str {
corpus.choose(rng).unwrap()
fn choose_word<'a, 'b, V>(
freq: &'b HashMap<String, V>,
rng: &'a mut ChaCha8Rng,
) -> &'b str {
freq.keys().choose(rng).unwrap()
};
let title = (0..rng.gen_range(2..10))
.map(|_| choose_word(&corpus, rng))
.map(|_| choose_word(&freq, rng))
.join(" ");
let mut word = freq.keys().choose(rng).unwrap();
@ -88,7 +88,7 @@ async fn main() {
.unwrap_or(word);
if rng.gen_bool(0.05) {
let url = (0..3).map(|_| choose_word(&corpus, rng)).join("-");
let url = (0..3).map(|_| choose_word(&freq, rng)).join("-");
content += &format!(" <a href=\"{}\">{}</a>", url, word);
} else if rng.gen_bool(0.01) {
content += ".<br>";