pub fn random_string(size: usize, charset: &[char]) -> StringExpand description
Generates a random string of a specified size using the provided charset.
§Arguments
size- The length of the generated string. Must be greater than 0.charset- A slice of characters to use for generating the string. Must not be empty.
§Panics
- If
sizeis less than or equal to 0. - If
charsetis empty.
§Examples
use lowdash::common::ALPHANUMERIC_CHARSET;
use lowdash::random_string;
let charset = ALPHANUMERIC_CHARSET;
let random_str = random_string(10, charset);
assert_eq!(random_str.len(), 10);
for c in random_str.chars() {
assert!(charset.contains(&c));
}