Before moving on to looking at how to use the most complex crates, let's take a look at some basic Rust crates. These are not a part of the standard library, but they are useful in many different kinds of projects. They should be known by all Rust developers since they are of general applicability.
Pseudo-random number generators – the rand crate
The ability to generate pseudo-random numbers is needed for several kinds of applications, especially for games. The rand crate is rather complex, but its basic usage is shown in the following example (named use_rand):
// Declare basic functions for pseudo-random number generators.
use rand::prelude::*;
fn main() {
// Create a pseudo-Random Number Generator for the current thread
let mut rng = thread_rng();
// Print an integer number
// between 0 (included) and 20 (excluded).
println!("{}", rng.gen_range(0, 20));
// Print a floating-point number
// between 0 (included) and...