13 lines
326 B
Rust
13 lines
326 B
Rust
pub fn get_random(len: usize) -> String {
|
|
use std::iter;
|
|
|
|
use rand::{distributions::Alphanumeric, rngs::ThreadRng, thread_rng, Rng};
|
|
|
|
let mut rng: ThreadRng = thread_rng();
|
|
|
|
iter::repeat(())
|
|
.map(|()| rng.sample(Alphanumeric))
|
|
.map(char::from)
|
|
.take(len)
|
|
.collect::<String>()
|
|
}
|