mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
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:
parent
dc840e1562
commit
7e688eb7e8
@ -165,17 +165,11 @@ impl<'c> Monero {
|
|||||||
|
|
||||||
fn random_prefix() -> String {
|
fn random_prefix() -> String {
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
const CHARSET: &[u8] = b"abcdefghijklmnopqrstuvwxyz";
|
|
||||||
const LEN: usize = 4;
|
|
||||||
let mut rng = rand::thread_rng();
|
|
||||||
|
|
||||||
let prefix: String = (0..LEN)
|
rand::thread_rng()
|
||||||
.map(|_| {
|
.sample_iter(rand::distributions::Alphanumeric)
|
||||||
let idx = rng.gen_range(0, CHARSET.len());
|
.take(4)
|
||||||
CHARSET[idx] as char
|
.collect()
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
prefix
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
Loading…
Reference in New Issue
Block a user