pub fn random_str(source: StrSource, len: usize) -> String {
    if len == 0 {
        return "".to_string();
    }
    let s = match source {
        StrSource::Digit => DIGIT_SOURCE,
        StrSource::Alpha => ALPHA_SOURCE,
        StrSource::AlphaAll => ALPHA_ALL_SOURCE,
        StrSource::DigitAlpha => DIGIT_ALPHA_SOURCE,
    };
    let max_len = s.len();
    let mut str = String::with_capacity(len);
    for _ in 0..len {
        let idx = rand::thread_rng().gen_range(0..max_len);
        str.push_str(&s[idx..idx+1]);
    }
    str
}
/// Generate random string using StringSource and length
Generate random string using StringSource and length
Generate random string using StringSource and length
pub fn random_str(source: StrSource, len: usize) -> String {
    if len == 0 {
        return "".to_string();
    }
    let s = match source {
        StrSource::Digit => DIGIT_SOURCE,
        StrSource::Alpha => ALPHA_SOURCE,
        StrSource::AlphaAll => ALPHA_ALL_SOURCE,
        StrSource::DigitAlpha => DIGIT_ALPHA_SOURCE,
    };
    let max_len = s.len();
    let mut str = String::with_capacity(len);
    for _ in 0..len {
        let idx = rand::thread_rng().gen_range(0..max_len);
        str.push_str(&s[idx..idx+1]);
    }
    str
}
pub fn random_str ( source : StrSource , len : usize ) -> String { if len == 0 { return " " . to_string ( ) ; } let s = match source { StrSource :: Digit => DIGIT_SOURCE , StrSource :: Alpha => ALPHA_SOURCE , StrSource :: AlphaAll => ALPHA_ALL_SOURCE , StrSource :: DigitAlpha => DIGIT_ALPHA_SOURCE , } ; let max_len = s . len ( ) ; let mut str = String :: with_capacity ( len ) ; for _ in 0 .. len { let idx = rand :: thread_rng ( ) . gen_range ( 0 .. max_len ) ; str . push_str ( & s [ idx .. idx + 1 ] ) ; } str }
Generate random string using StringSource and length
Generate random string using StringSource and length
source
StrSource
len
usize