Don't reinvent the wheel

`Alphanumeric` includes uppercase letters and digits as well but
for our usecase, that doesn't matter.
This commit is contained in:
Thomas Eizinger 2021-04-16 13:11:26 +10:00
parent dc840e1562
commit 7e688eb7e8
No known key found for this signature in database
GPG Key ID: 651AC83A6C6C8B96

View File

@ -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)]