To generate a random number in Rust, you will need the rand
crate.
Add rand
to your Cargo.toml
file:
main.rs30 chars3 lines
Then, you can use the Rng
trait to generate a random number. Here's an example that generates a random integer between 1 and 100:
main.rs245 chars9 lines
This will output a random number between 1 and 100 every time the program is run.
gistlibby LogSnag