Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.5"
rand = "0.9.0"
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn main() {
println!("Guess the number!");

// ANCHOR: ch07-04
let secret_number = rand::thread_rng().gen_range(1..=100);
let secret_number = rand::rng().random_range(1..=100);
// ANCHOR_END: ch07-04

println!("The secret number is: {secret_number}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.5"
rand = "0.9.0"
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rand::Rng;
fn main() {
println!("Guess the number!");

let secret_number = rand::thread_rng().gen_range(1..=100);
let secret_number = rand::rng().random_range(1..=100);

loop {
println!("Please input your guess.");
Expand Down
11 changes: 5 additions & 6 deletions src/ch02-00-guessing-game-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -525,20 +525,20 @@ random number generators implement, and this trait must be in scope for us to
use those methods. Chapter 10 will cover traits in detail.

Next, we’re adding two lines in the middle. In the first line, we call the
`rand::thread_rng` function that gives us the particular random number
`rand::rng` function that gives us the particular random number
generator we’re going to use: one that is local to the current thread of
execution and is seeded by the operating system. Then we call the `gen_range`
execution and is seeded by the operating system. Then we call the `random_range`
method on the random number generator. This method is defined by the `Rng`
trait that we brought into scope with the `use rand::Rng;` statement. The
`gen_range` method takes a range expression as an argument and generates a
`random_range` method takes a range expression as an argument and generates a
random number in the range. The kind of range expression we’re using here takes
the form `start..=end` and is inclusive on the lower and upper bounds, so we
need to specify `1..=100` to request a number between 1 and 100.

> Note: You won’t just know which traits to use and which methods and functions
> to call from a crate, so each crate has documentation with instructions for
> using it. Another neat feature of Cargo is that running the `cargo doc
> --open` command will build documentation provided by all your dependencies
--open` command will build documentation provided by all your dependencies
> locally and open it in your browser. If you’re interested in other
> functionality in the `rand` crate, for example, run `cargo doc --open` and
> click `rand` in the sidebar on the left.
Expand Down Expand Up @@ -619,8 +619,7 @@ might encounter and they make sure you handle them all. These features will be
covered in detail in Chapter 6 and Chapter 19, respectively.

Let’s walk through an example with the `match` expression we use here. Say that
the user has guessed 50 and the randomly generated secret number this time is
38.
the user has guessed 50 and the randomly generated secret number this time is 38.

When the code compares 50 to 38, the `cmp` method will return
`Ordering::Greater` because 50 is greater than 38. The `match` expression gets
Expand Down