tits-rs 0.1.0

(touch) typing in terminal space
Documentation
use rand::seq::SliceRandom;
use rand::thread_rng;
use std::fs::File;
use std::io::{BufRead, BufReader};

pub fn gen_text() -> String {
    let file = File::open("./data/common.txt").unwrap();
    let reader = BufReader::new(file);
    let words: Vec<String> = reader.lines().filter_map(Result::ok).collect();

    // Ensure that there are at least 750 words in the file
    if words.len() < 750 {
        panic!("File must contain at least 750 words");
    }

    let mut rng = thread_rng();
    let indices: Vec<usize> = (0..750).collect();
    let selected_indices: Vec<_> = indices.choose_multiple(&mut rng, 750).cloned().collect();

    let mut random_words = String::new();
    for i in selected_indices {
        random_words.push_str(&words[i]);
        random_words.push(' ');
    }

    random_words
}