Rust Random Number Generation Generating Characters with Rand


To generate characters, you can utilize the thread-local random number generator function, random.

fn main() {
    let tuple = rand::random::<(f64, char)>();
    println!("{:?}", tuple)

For occasional or singular requests, such as the one above, this is a reasonable efficient method. However, if you intend to generate more than a handful of numbers, you will find caching the generator will be more efficient.

You should expect to the see the following output in this case.

$ cargo run
     Running `target/debug/so`
(0.906881, '\u{9edc}')