For generate a random string with fixed size in Rust, we can use Alphanumeric
trait from rand
crate:
use rand::{distributions::Alphanumeric, Rng}; // 0.8
fn main() {
let s: String = rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(7)
.map(char::from)
.collect();
println!("{}", s);
}