Rust Random Number Generation Generating Characters with Rand

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

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}')


Got any Rust Question?