pub fn custom_random_bytes<F>(bytes: usize, mut rng: F) -> String
where
    F: FnMut(&mut [u8]),
{
    let required_slice_size = encoding::compute_encoded_size(bytes);
    let mut result = Vec::with_capacity(required_slice_size);

    // Complete groups.
    let mut chunk = [0; 11];
    for _ in 0..(bytes >> 3) {
        rng(&mut chunk);

        let encoded = encoding::compute_chunk(&chunk);

        result.extend_from_slice(&encoded);
    }

    // Last incomplete group.
    let last_group_length = bytes - (bytes >> 3 << 3);
    if last_group_length != 0 {
        rng(&mut chunk);

        let chunk = &chunk[11 - last_group_length..];
        let encoded = encoding::compute_chunk(chunk);
        let elements_to_write = encoding::compute_encoded_size(last_group_length);

        result.extend_from_slice(&encoded[..elements_to_write]);
    }

    unsafe { String::from_utf8_unchecked(result) }
}
/// Generates a random G60 string of `bytes` length using a custom random generator.
Generates a random G60 string of `bytes` length using a custom random generator.
Generates a random G60 string of ` bytes ` length using a custom random generator .
pub fn custom_random_bytes<F>(bytes: usize, mut rng: F) -> String
where
    F: FnMut(&mut [u8]),
{
    let required_slice_size = encoding::compute_encoded_size(bytes);
    let mut result = Vec::with_capacity(required_slice_size);
    // Complete groups.
    let mut chunk = [0; 11];
    for _ in 0..(bytes >> 3) {
        rng(&mut chunk);
        let encoded = encoding::compute_chunk(&chunk);
        result.extend_from_slice(&encoded);
    }
    // Last incomplete group.
    let last_group_length = bytes - (bytes >> 3 << 3);
    if last_group_length != 0 {
        rng(&mut chunk);
        let chunk = &chunk[11 - last_group_length..];
        let encoded = encoding::compute_chunk(chunk);
        let elements_to_write = encoding::compute_encoded_size(last_group_length);
        result.extend_from_slice(&encoded[..elements_to_write]);
    }
    unsafe { String::from_utf8_unchecked(result) }
}
pub fn custom_random_bytes < F > ( bytes : usize , mut rng : F ) -> String where F : FnMut ( & mut [ u8 ] ) , { let required_slice_size = encoding :: compute_encoded_size ( bytes ) ; let mut result = Vec :: with_capacity ( required_slice_size ) ; // Complete groups. let mut chunk = [ 0 ; 11 ] ; for _ in 0 .. ( bytes >> 3 ) { rng ( & mut chunk ) ; let encoded = encoding :: compute_chunk ( & chunk ) ; result . extend_from_slice ( & encoded ) ; } // Last incomplete group. let last_group_length = bytes - ( bytes >> 3 << 3 ) ; if last_group_length != 0 { rng ( & mut chunk ) ; let chunk = & chunk [ 11 - last_group_length .. ] ; let encoded = encoding :: compute_chunk ( chunk ) ; let elements_to_write = encoding :: compute_encoded_size ( last_group_length ) ; result . extend_from_slice ( & encoded [ .. elements_to_write ] ) ; } unsafe { String :: from_utf8_unchecked ( result ) } }
Generates a random G60 string of `bytes` length using a custom random generator.
Generates a random G60 string of ` bytes ` length using a custom random generator .
bytes
usize
rng
F
bytes
usize
rng
F