From 56ec8d6305bdb7db3c00504478e4c69b106dc943 Mon Sep 17 00:00:00 2001 From: Ariel Mashraki Date: Sat, 22 Oct 2016 19:56:03 +0300 Subject: [PATCH] example: generate random string at the end --- examples/multi.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/examples/multi.rs b/examples/multi.rs index dffea902..c650bafa 100644 --- a/examples/multi.rs +++ b/examples/multi.rs @@ -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())); }); } @@ -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::(); + // [0-9a-f] + if b > 47 && b < 58 || b > 96 && b < 103 { + v.push(b); + } + } + std::str::from_utf8(&v).unwrap().to_string() +}