In this video, generate the secret number using the rand crate.
- [Instructor] Next, we need to generate a secret number…that the user will try to guess.…The secret number should be different every time,…so that the game is fun to play more than once.…Let's use a random number between one and 100,…so that the game isn't too difficult.…Rust doesn't yet include a random number functionality…in a standard library.…However, we have the Rust crate called rand.…Before we can write code that uses rand,…we need to modify the cargo.toml file…that cargo has generated for us.…
Let's open up that file now and add the following line…to the beneath on line seven.…Rand equals zero point three dot one four.…Cargo understands semantic versioning,…which is a standard for writing version numbers.…The number zero dot three dot 14…means any version that has a public API…compatible with version zero dot three dot 14…of the rand crate.…
Now we can go to main.rs and start using rand.…Let's add an extern crate rand at the beginning.…Extern crate rand.…So we are letting Rust know…that we will be using that external dependency.…
- Installing Rust
- Data types
- Adjusting memory allocation
- Setting up race conditions
- Working with functions
- Exploring references and borrowing
- Using structs
- Method syntax
- Demonstrating recoverable errors with Result
- Working with enums
- Getting user input
Skill Level Beginner
Programming Foundations: Data Structures (2014)with Simon Allardice2h 29m Intermediate
1. Hello, Rust!
2. Basic Programming Concepts
3. Ownership in Rust
4. Data Handling and Pattern Matching in Rust
5. Error Handling
6. Sample Rust Project: The Guessing Game
Next steps1m 14s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.