Skip to main content

random_string

Function random_string 

Source
pub fn random_string(size: usize) -> String
Expand description

A random alphanumeric string of size characters, uniformly distributed over the 62-char alphabet.

Uses rejection sampling rather than upstream’s byte % 62. The largest multiple of 62 at or below 256 is 248, so bytes 248..=255 are rejected and redrawn. Expected redraws are about 3.2%, which is not worth a smarter scheme.