Skip to content

Update guessing game to rand 0.10#4680

Closed
sengmonkham wants to merge 1 commit into
rust-lang:mainfrom
sengmonkham:update-rand-0.10
Closed

Update guessing game to rand 0.10#4680
sengmonkham wants to merge 1 commit into
rust-lang:mainfrom
sengmonkham:update-rand-0.10

Conversation

@sengmonkham

Copy link
Copy Markdown

Fix: #4679

Fixes the ch02 guessing game chapter, which was using rand 0.8.5 with APIs that have since been renamed in rand 0.9 and rand 0.10.

What changed

rand API migration:

Old (rand 0.8.5) New (rand 0.10)
rand = "0.8.5" rand = "0.10"
use rand::Rng use rand::RngExt
rand::thread_rng().gen_range(1..=100) rand::rng().random_range(1..=100)

Files updated:

  • listings/ch02-guessing-game-tutorial/*/Cargo.toml — version bump (×8)
  • listings/ch02-guessing-game-tutorial/*/Cargo.lock — regenerated, pinning rand v0.10.0 (×8)
  • listings/ch02-guessing-game-tutorial/*/src/main.rs — API calls updated (×7)
  • src/ch02-00-guessing-game-tutorial.md — prose, version specifiers, and cargo build console output updated
  • src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md — updated rand::thread_rng/Rng references

Migrate all ch02 guessing game listings from rand 0.8.5 to rand 0.10.

API changes applied:
- rand::thread_rng() -> rand::rng()
- .gen_range(1..=100) -> .random_range(1..=100)
- use rand::Rng -> use rand::RngExt (random_range moved to RngExt in 0.10)
- rand = "0.8.5" -> rand = "0.10" in all Cargo.toml files

Files changed:
- 8x Cargo.toml (version bump)
- 8x Cargo.lock (regenerated, pinning rand v0.10.0)
- 7x src/main.rs (API calls updated)
- src/ch02-00-guessing-game-tutorial.md (prose + console output updated)
- src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md (prose updated)
@marcosnathan

Copy link
Copy Markdown

Thanks for this PR. I started studying Rust and I was stuck at this step

@santhosh-john

Copy link
Copy Markdown

@sengmonkham: Could you please resolve the lint issues so this can be ready for merge? This change is particularly helpful for anyone new to the Rust ecosystem and is using the rust-book as their starting point. The example in the book still reflects an older API, which was updated in the Feb 2021 release.

Aligning the code with the current API will make the learning experience smoother and avoid confusion for beginners. Thanks in advance!

@santhosh-john

Copy link
Copy Markdown

... or just use: let secret_number = rand::random_range(1..=100);

@carols10cents

Copy link
Copy Markdown
Member

This is a duplicate of #4756. Please check existing pull requests before duplicating work.

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.

Bug: guessing game rand version

4 participants