diff --git a/src/distributions/other.rs b/src/distributions/other.rs index c95060e5104..572095e5326 100644 --- a/src/distributions/other.rs +++ b/src/distributions/other.rs @@ -16,7 +16,7 @@ use crate::Rng; // ----- Sampling distributions ----- -/// Sample a `char`, uniformly distributed over ASCII letters and numbers: +/// Sample a `char` or `u8`, uniformly distributed over ASCII letters and numbers: /// a-z, A-Z and 0-9. /// /// # Example @@ -62,6 +62,13 @@ impl Distribution for Standard { impl Distribution for Alphanumeric { fn sample(&self, rng: &mut R) -> char { + let byte: u8 = self.sample(rng); + byte as char + } +} + +impl Distribution for Alphanumeric { + fn sample(&self, rng: &mut R) -> u8 { const RANGE: u32 = 26 + 26 + 10; const GEN_ASCII_STR_CHARSET: &[u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ\ abcdefghijklmnopqrstuvwxyz\ @@ -73,7 +80,7 @@ impl Distribution for Alphanumeric { loop { let var = rng.next_u32() >> (32 - 6); if var < RANGE { - return GEN_ASCII_STR_CHARSET[var as usize] as char; + return GEN_ASCII_STR_CHARSET[var as usize]; } } }