pub fn generate_with_rng<R: Rng>(
length: usize,
charset: &[u8],
rng: &mut R,
) -> String
Expand description
Generates a random string of a specified length using a given character set and RNG.
§Arguments
length
- The length of the generated string.charset
- A slice of bytes representing the character set to use for generating the string.rng
- A mutable reference to an RNG implementing theRng
trait.
§Returns
A String
containing randomly selected characters from the provided character set.
§Examples
use rand::SeedableRng;
use rand::rngs::SmallRng;
use advanced_random_string::{charset, random_string};
let mut rng = SmallRng::from_entropy();
let random_string = random_string::generate_with_rng(10, charset::BASE62, &mut rng);
println!("Generated string: {}", random_string);