Skip to content

Fix random number generation method in src/main.rs#4498

Closed
Vianpyro wants to merge 1 commit into
rust-lang:mainfrom
Vianpyro:patch-1
Closed

Fix random number generation method in src/main.rs#4498
Vianpyro wants to merge 1 commit into
rust-lang:mainfrom
Vianpyro:patch-1

Conversation

@Vianpyro
Copy link
Copy Markdown

@Vianpyro Vianpyro commented Sep 8, 2025

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).

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).
@carols10cents
Copy link
Copy Markdown
Member

This is a duplicate of #4254. Thanks though!

@Vianpyro Vianpyro deleted the patch-1 branch September 20, 2025 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants