From d3324671603dc5f5df6dd22a723925acd98ff254 Mon Sep 17 00:00:00 2001 From: Vianney Veremme <10519369+Vianpyro@users.noreply.github.com> Date: Mon, 8 Sep 2025 10:47:15 -0400 Subject: [PATCH] Fix random number generation method in main.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Rust Book currently shows `rand::thread_rng().gen_range(1..=100)` for generating the secret number. This API has been deprecated in favor of the newer `rand::rng().random_range(1..=100)` introduced in recent versions of the `rand` crate. This commit updates the example in `main.rs` to use the current recommended method, ensuring that readers following along with the book won’t encounter warnings or confusion when compiling the code with up-to-date dependencies. No behavioral changes are introduced: the secret number is still generated uniformly at random between 1 and 100 (inclusive). --- listings/ch02-guessing-game-tutorial/listing-02-06/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/listings/ch02-guessing-game-tutorial/listing-02-06/src/main.rs b/listings/ch02-guessing-game-tutorial/listing-02-06/src/main.rs index bd728b4dc2..a9be6db759 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-06/src/main.rs +++ b/listings/ch02-guessing-game-tutorial/listing-02-06/src/main.rs @@ -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.");