Última actividad 1748530914

lol.rs Sin formato
1use rand::{distributions::Alphanumeric, Rng};
2use std::fs::File;
3use std::io::Write;
4
5fn generate_random_string() -> String {
6 rand::thread_rng()
7 .sample_iter(&Alphanumeric)
8 .take(6)
9 .map(char::from)
10 .collect()
11}
12
13fn 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
21fn 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}