From 7e688eb7e830e6e042d0d73e41724582a73b8535 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Fri, 16 Apr 2021 13:11:26 +1000 Subject: [PATCH] Don't reinvent the wheel `Alphanumeric` includes uppercase letters and digits as well but for our usecase, that doesn't matter. --- monero-harness/src/lib.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/monero-harness/src/lib.rs b/monero-harness/src/lib.rs index 5f69cd43..090ac7e4 100644 --- a/monero-harness/src/lib.rs +++ b/monero-harness/src/lib.rs @@ -165,17 +165,11 @@ impl<'c> Monero { fn random_prefix() -> String { use rand::Rng; - const CHARSET: &[u8] = b"abcdefghijklmnopqrstuvwxyz"; - const LEN: usize = 4; - let mut rng = rand::thread_rng(); - let prefix: String = (0..LEN) - .map(|_| { - let idx = rng.gen_range(0, CHARSET.len()); - CHARSET[idx] as char - }) - .collect(); - prefix + rand::thread_rng() + .sample_iter(rand::distributions::Alphanumeric) + .take(4) + .collect() } #[derive(Clone, Debug)]