DraxCodes revised this gist . Go to revision
1 file changed, 27 insertions
lol.rs(file created)
@@ -0,0 +1,27 @@ | |||
1 | + | use rand::{distributions::Alphanumeric, Rng}; | |
2 | + | use std::fs::File; | |
3 | + | use std::io::Write; | |
4 | + | ||
5 | + | fn generate_random_string() -> String { | |
6 | + | rand::thread_rng() | |
7 | + | .sample_iter(&Alphanumeric) | |
8 | + | .take(6) | |
9 | + | .map(char::from) | |
10 | + | .collect() | |
11 | + | } | |
12 | + | ||
13 | + | fn write_to_file(filename: &str, count: usize) -> std::io::Result<()> { | |
14 | + | let mut file = File::create(filename)?; | |
15 | + | for _ in 0..count { | |
16 | + | writeln!(file, "{}", generate_random_string())?; | |
17 | + | } | |
18 | + | Ok(()) | |
19 | + | } | |
20 | + | ||
21 | + | fn main() { | |
22 | + | if let Err(e) = write_to_file("random_strings.txt", 300_000) { | |
23 | + | eprintln!("Error writing to file: {}", e); | |
24 | + | } else { | |
25 | + | println!("Random strings generated and saved to random_strings.txt"); | |
26 | + | } | |
27 | + | } |
Newer
Older