Here is an example code snippet to generate a random number between 1 and 10 in Rust using the built-in rand
crate:
main.rs182 chars8 lines
Explanation:
rand::Rng
trait provides methods for generating random numbers.rand::thread_rng()
creates a random number generator that is seeded from the operating system's entropy.rng.gen_range(1..=10)
generates a random number between 1 and 10 (inclusive on both ends).println!
macro.gistlibby LogSnag