Created
April 23, 2015 07:47
-
-
Save dplord/fa02a1cb27f779d70deb to your computer and use it in GitHub Desktop.
tenMillionFile.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::rand; | |
use std::rand::Rng; | |
use std::old_io::BufferedReader; | |
use std::old_io::File; | |
fn write_file(path: &str, s: &str) | |
{ | |
use std::old_io::{BufferedWriter, File}; | |
let file = File::create(&Path::new(path)).unwrap(); | |
let mut writer = BufferedWriter::new(file); | |
writer.write_str(s).unwrap(); | |
writer.flush().unwrap(); | |
} | |
fn my_rand() -> i32 { | |
let mut rng = rand::thread_rng(); | |
let n: i32 = rng.gen_range(1, 10000); | |
n | |
} | |
fn main() | |
{ | |
for i in 0..10000 | |
{ | |
let mut s = String::with_capacity(262144); | |
for j in 0..10000 | |
{ | |
let s_one:String = format!("{}\t{}\t{}\t{}\t{}", | |
my_rand(), | |
my_rand(), | |
my_rand(), | |
my_rand(), | |
my_rand() | |
); | |
s.push_str(&s_one); | |
if(j != 9999) { s.push_str("\n"); } | |
}//生成10000行随机数 | |
//println!("{}\n", i); | |
let path: String = format!("/tmp/out/r_{}", i); | |
write_file(&path, &s); | |
}// 生成10000个文件 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment