prophecy generator
This commit is contained in:
28
prophecies/src/main.rs
Normal file
28
prophecies/src/main.rs
Normal 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(())
|
||||
}
|
Reference in New Issue
Block a user