random_string

Function random_string 

Source
pub fn random_string(size: usize, charset: &[char]) -> String
Expand 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 size is less than or equal to 0.
  • If charset is 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));
}