lol.rs
Eredeti
use rand::{distributions::Alphanumeric, Rng};
use std::fs::File;
use std::io::Write;
fn generate_random_string() -> String {
rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(6)
.map(char::from)
.collect()
}
fn write_to_file(filename: &str, count: usize) -> std::io::Result<()> {
let mut file = File::create(filename)?;
for _ in 0..count {
writeln!(file, "{}", generate_random_string())?;
}
Ok(())
}
fn main() {
if let Err(e) = write_to_file("random_strings.txt", 300_000) {
eprintln!("Error writing to file: {}", e);
} else {
println!("Random strings generated and saved to random_strings.txt");
}
}
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 | } |