macro_rules! random_choice {
($range:expr, $choice_set:expr) => { ... };
($($range:expr),+; $split:expr; $choice_set:expr) => { ... };
}
Expand description
Generate a random string by choosing ones from given candidates.
Candidates should be Vec<&str>
or [&'a str]
.
§Examples
Here’s an example rewritten from the original JavaScript code.
static DIGHT_MAP: [&'static str; 17] = [
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "10",
];
let rc_1 = random_choice!(32, DIGHT_MAP);
let rc_2 = random_choice!(8, 4, 4, 4, 12; "-"; DIGHT_MAP); // like `8310B0E0A-40105-9EC3-8298-36C75D10FEA59`