prophecy generator

This commit is contained in:
deadvey
2024-12-24 17:42:11 +00:00
parent 449c5fa85b
commit 76257b7483
4 changed files with 184 additions and 0 deletions

28
prophecies/src/main.rs Normal file
View File

@@ -0,0 +1,28 @@
use std::fs;
use std::io;
use rand::Rng;
fn main() -> io::Result<()> {
// Read the file that contains every prophecy line in the series
let file_contents: String = fs::read_to_string("prophecies")?;
// Determine the name of the prophecy by picking a random word in file
let split_into_words = file_contents.split_whitespace().collect::<Vec<_>>();
let name = split_into_words[rand::thread_rng().gen_range(0..split_into_words.len())];
println!("THE PROPHECY OF {}:\n", name.to_uppercase());
// Randomly decide how long the prophecy will be, range of 4 to 30
let number_of_lines = rand::thread_rng().gen_range(4..30);
// Split file into lines
let split_string = file_contents.split("\n").collect::<Vec<_>>();
let lines_in_string = split_string.len();
// Iterate for "number_of_lines" and each time pick a random line in the file
for _i in 0..number_of_lines {
let line_index = rand::thread_rng().gen_range(0..lines_in_string); // Pick random line
println!("{}",split_string[line_index]); // Print the random line
}
Ok(())
}