Skip to content

Latest commit

 

History

History
23 lines (16 loc) · 593 Bytes

rand-passwd.zh.md

File metadata and controls

23 lines (16 loc) · 593 Bytes

从一组字母+数字的字符,创建随机密码

[![rand-badge]][rand] [![cat-os-badge]][cat-os]

随机生成,给定长度的 ASCII 字符串,字符范围是A-Z, a-z, 0-9,运用Alphanumeric (字母+数字)样品。

extern crate rand;

use rand::{thread_rng, Rng};
use rand::distributions::Alphanumeric;

fn main() {
    let rand_string: String = thread_rng()
        .sample_iter(&Alphanumeric)
        .take(30)
        .collect();

    println!("{}", rand_string);
}