Using external crates
📖 Scenario: You want to use a popular external crate called rand to generate random numbers in your Rust program. This is common when you need random values for games, simulations, or testing.
🎯 Goal: Learn how to add an external crate to your Rust project and use it to generate a random number between 1 and 10.
📋 What You'll Learn
Create a new Rust project with Cargo
Add the
rand crate as a dependency in Cargo.tomlImport the
rand crate in your main.rsGenerate and print a random number between 1 and 10
💡 Why This Matters
🌍 Real World
Random numbers are used in games, simulations, and testing to add unpredictability and variety.
💼 Career
Knowing how to use external crates is essential for Rust developers to reuse code and add functionality quickly.
Progress0 / 4 steps