Skip to content

Commit

Permalink
example: generate random string at the end
Browse files Browse the repository at this point in the history
  • Loading branch information
a8m committed Oct 22, 2016
1 parent 8f86efa commit 56ec8d6
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion examples/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn main() {
thread::sleep(Duration::from_millis(100));
pb.tick();
}
pb.finish_print(&format!("Bar {} completed !", i));
pb.finish_print(&format!("{}: Pull complete", rand_string()));
});
}

Expand All @@ -60,3 +60,15 @@ fn main() {

println!("\nall bars done!\n");
}

fn rand_string() -> String {
let mut v = Vec::new();
while v.len() < 12 {
let b = rand::random::<u8>();
// [0-9a-f]
if b > 47 && b < 58 || b > 96 && b < 103 {
v.push(b);
}
}
std::str::from_utf8(&v).unwrap().to_string()
}

0 comments on commit 56ec8d6

Please sign in to comment.