From 41a01f3e9e89056f765dc0e22dc776c8523d2309 Mon Sep 17 00:00:00 2001 From: Abhishek Shinde Date: Mon, 18 May 2026 20:01:03 +0530 Subject: [PATCH 1/2] doc: upgrade rand dependency to v0.10.1 in book listings and text Upgrades the 'rand' crate dependency from v0.8.5 to v0.10.1 across all chapter listings and updates the corresponding book narrative to reflect the new API structure. Key Changes: - Manifests: Updated 14 Cargo.toml files in listings to point to rand 0.10.1. - Source Code: Migrated 11 main.rs and lib.rs source files under listings/ to: - Bring the new extension trait 'rand::RngExt' into scope instead of 'rand::Rng'. - Replace 'rand::thread_rng().gen_range(1..=100)' with 'rand::rng().random_range(1..=100)'. - Chapter 1: Updated the offline caching command in ch01-01-installation.md to refer to rand@0.10.1. - Chapter 2: Updated ch02-00-guessing-game-tutorial.md to explain RngExt, rand::rng, and random_range. Adjusted all SemVer examples, compiler outputs, and hypotheticals to use 0.10.1 / 0.10.2 / 0.11.0. - Chapter 7: Updated the module path and import system explanation in ch07-04-bringing-paths-into-scope-with-the-use-keyword.md to target the new traits/functions. - Chapter 14: Updated simulated cargo output in ch14-03-cargo-workspaces.md showing rand v0.10.1 being compiled. --- .../listing-02-02/Cargo.toml | 2 +- .../listing-02-03/Cargo.toml | 2 +- .../listing-02-03/src/main.rs | 4 +- .../listing-02-04/Cargo.toml | 2 +- .../listing-02-04/src/main.rs | 4 +- .../listing-02-05/Cargo.toml | 2 +- .../listing-02-05/src/main.rs | 4 +- .../listing-02-06/Cargo.toml | 2 +- .../listing-02-06/src/main.rs | 4 +- .../Cargo.toml | 2 +- .../src/main.rs | 4 +- .../no-listing-04-looping/Cargo.toml | 2 +- .../no-listing-04-looping/src/main.rs | 4 +- .../no-listing-05-quitting/Cargo.toml | 2 +- .../no-listing-05-quitting/src/main.rs | 4 +- .../listing-07-18/Cargo.toml | 2 +- .../listing-07-18/src/main.rs | 4 +- .../no-listing-01-use-std-unnested/Cargo.toml | 2 +- .../src/main.rs | 4 +- .../listing-09-13/Cargo.toml | 2 +- .../listing-09-13/src/main.rs | 4 +- .../Cargo.toml | 2 +- .../src/main.rs | 4 +- .../add/add_one/Cargo.toml | 2 +- .../add/add_one/Cargo.toml | 2 +- src/ch01-01-installation.md | 2 +- src/ch02-00-guessing-game-tutorial.md | 42 +++++++++---------- ...g-paths-into-scope-with-the-use-keyword.md | 4 +- src/ch14-03-cargo-workspaces.md | 4 +- 29 files changed, 62 insertions(+), 62 deletions(-) diff --git a/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.toml b/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.toml index eba27a883c..22f02e1859 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.toml +++ b/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.toml @@ -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.10.1" diff --git a/listings/ch02-guessing-game-tutorial/listing-02-03/Cargo.toml b/listings/ch02-guessing-game-tutorial/listing-02-03/Cargo.toml index eba27a883c..22f02e1859 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-03/Cargo.toml +++ b/listings/ch02-guessing-game-tutorial/listing-02-03/Cargo.toml @@ -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.10.1" diff --git a/listings/ch02-guessing-game-tutorial/listing-02-03/src/main.rs b/listings/ch02-guessing-game-tutorial/listing-02-03/src/main.rs index 0ae11e3d41..c63125c87f 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-03/src/main.rs +++ b/listings/ch02-guessing-game-tutorial/listing-02-03/src/main.rs @@ -2,14 +2,14 @@ use std::io; // ANCHOR: ch07-04 -use rand::Rng; +use rand::RngExt; fn main() { // ANCHOR_END: ch07-04 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}"); diff --git a/listings/ch02-guessing-game-tutorial/listing-02-04/Cargo.toml b/listings/ch02-guessing-game-tutorial/listing-02-04/Cargo.toml index eba27a883c..22f02e1859 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-04/Cargo.toml +++ b/listings/ch02-guessing-game-tutorial/listing-02-04/Cargo.toml @@ -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.10.1" diff --git a/listings/ch02-guessing-game-tutorial/listing-02-04/src/main.rs b/listings/ch02-guessing-game-tutorial/listing-02-04/src/main.rs index fae3c29c6f..7a00a92b5e 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-04/src/main.rs +++ b/listings/ch02-guessing-game-tutorial/listing-02-04/src/main.rs @@ -2,14 +2,14 @@ use std::cmp::Ordering; use std::io; -use rand::Rng; +use rand::RngExt; fn main() { // --snip-- // ANCHOR_END: here println!("Guess the number!"); - let secret_number = rand::thread_rng().gen_range(1..=100); + let secret_number = rand::rng().random_range(1..=100); println!("The secret number is: {secret_number}"); diff --git a/listings/ch02-guessing-game-tutorial/listing-02-05/Cargo.toml b/listings/ch02-guessing-game-tutorial/listing-02-05/Cargo.toml index eba27a883c..22f02e1859 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-05/Cargo.toml +++ b/listings/ch02-guessing-game-tutorial/listing-02-05/Cargo.toml @@ -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.10.1" diff --git a/listings/ch02-guessing-game-tutorial/listing-02-05/src/main.rs b/listings/ch02-guessing-game-tutorial/listing-02-05/src/main.rs index 0ca4853d49..b9d107b03a 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-05/src/main.rs +++ b/listings/ch02-guessing-game-tutorial/listing-02-05/src/main.rs @@ -1,12 +1,12 @@ use std::cmp::Ordering; use std::io; -use rand::Rng; +use rand::RngExt; 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); println!("The secret number is: {secret_number}"); diff --git a/listings/ch02-guessing-game-tutorial/listing-02-06/Cargo.toml b/listings/ch02-guessing-game-tutorial/listing-02-06/Cargo.toml index eba27a883c..22f02e1859 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-06/Cargo.toml +++ b/listings/ch02-guessing-game-tutorial/listing-02-06/Cargo.toml @@ -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.10.1" 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..46e278558f 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 @@ -1,12 +1,12 @@ use std::cmp::Ordering; use std::io; -use rand::Rng; +use rand::RngExt; 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."); diff --git a/listings/ch02-guessing-game-tutorial/no-listing-03-convert-string-to-number/Cargo.toml b/listings/ch02-guessing-game-tutorial/no-listing-03-convert-string-to-number/Cargo.toml index eba27a883c..22f02e1859 100644 --- a/listings/ch02-guessing-game-tutorial/no-listing-03-convert-string-to-number/Cargo.toml +++ b/listings/ch02-guessing-game-tutorial/no-listing-03-convert-string-to-number/Cargo.toml @@ -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.10.1" diff --git a/listings/ch02-guessing-game-tutorial/no-listing-03-convert-string-to-number/src/main.rs b/listings/ch02-guessing-game-tutorial/no-listing-03-convert-string-to-number/src/main.rs index e4ec0c9af1..fb6dea0519 100644 --- a/listings/ch02-guessing-game-tutorial/no-listing-03-convert-string-to-number/src/main.rs +++ b/listings/ch02-guessing-game-tutorial/no-listing-03-convert-string-to-number/src/main.rs @@ -1,12 +1,12 @@ use std::cmp::Ordering; use std::io; -use rand::Rng; +use rand::RngExt; 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); println!("The secret number is: {secret_number}"); diff --git a/listings/ch02-guessing-game-tutorial/no-listing-04-looping/Cargo.toml b/listings/ch02-guessing-game-tutorial/no-listing-04-looping/Cargo.toml index eba27a883c..22f02e1859 100644 --- a/listings/ch02-guessing-game-tutorial/no-listing-04-looping/Cargo.toml +++ b/listings/ch02-guessing-game-tutorial/no-listing-04-looping/Cargo.toml @@ -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.10.1" diff --git a/listings/ch02-guessing-game-tutorial/no-listing-04-looping/src/main.rs b/listings/ch02-guessing-game-tutorial/no-listing-04-looping/src/main.rs index 934be44446..a1dd57aeeb 100644 --- a/listings/ch02-guessing-game-tutorial/no-listing-04-looping/src/main.rs +++ b/listings/ch02-guessing-game-tutorial/no-listing-04-looping/src/main.rs @@ -1,12 +1,12 @@ use std::cmp::Ordering; use std::io; -use rand::Rng; +use rand::RngExt; 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); // ANCHOR: here // --snip-- diff --git a/listings/ch02-guessing-game-tutorial/no-listing-05-quitting/Cargo.toml b/listings/ch02-guessing-game-tutorial/no-listing-05-quitting/Cargo.toml index eba27a883c..22f02e1859 100644 --- a/listings/ch02-guessing-game-tutorial/no-listing-05-quitting/Cargo.toml +++ b/listings/ch02-guessing-game-tutorial/no-listing-05-quitting/Cargo.toml @@ -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.10.1" diff --git a/listings/ch02-guessing-game-tutorial/no-listing-05-quitting/src/main.rs b/listings/ch02-guessing-game-tutorial/no-listing-05-quitting/src/main.rs index 77cbc938e8..5957e1144c 100644 --- a/listings/ch02-guessing-game-tutorial/no-listing-05-quitting/src/main.rs +++ b/listings/ch02-guessing-game-tutorial/no-listing-05-quitting/src/main.rs @@ -1,12 +1,12 @@ use std::cmp::Ordering; use std::io; -use rand::Rng; +use rand::RngExt; 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); println!("The secret number is: {secret_number}"); diff --git a/listings/ch07-managing-growing-projects/listing-07-18/Cargo.toml b/listings/ch07-managing-growing-projects/listing-07-18/Cargo.toml index 9f9c4acb96..29e22e9a67 100644 --- a/listings/ch07-managing-growing-projects/listing-07-18/Cargo.toml +++ b/listings/ch07-managing-growing-projects/listing-07-18/Cargo.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024" [dependencies] -rand = "0.8.5" +rand = "0.10.1" diff --git a/listings/ch07-managing-growing-projects/listing-07-18/src/main.rs b/listings/ch07-managing-growing-projects/listing-07-18/src/main.rs index 2f69412a4c..1b947ff9a3 100644 --- a/listings/ch07-managing-growing-projects/listing-07-18/src/main.rs +++ b/listings/ch07-managing-growing-projects/listing-07-18/src/main.rs @@ -1,4 +1,4 @@ -use rand::Rng; +use rand::RngExt; // ANCHOR: here // --snip-- use std::{cmp::Ordering, io}; @@ -8,7 +8,7 @@ use std::{cmp::Ordering, io}; 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); println!("The secret number is: {secret_number}"); diff --git a/listings/ch07-managing-growing-projects/no-listing-01-use-std-unnested/Cargo.toml b/listings/ch07-managing-growing-projects/no-listing-01-use-std-unnested/Cargo.toml index eba27a883c..22f02e1859 100644 --- a/listings/ch07-managing-growing-projects/no-listing-01-use-std-unnested/Cargo.toml +++ b/listings/ch07-managing-growing-projects/no-listing-01-use-std-unnested/Cargo.toml @@ -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.10.1" diff --git a/listings/ch07-managing-growing-projects/no-listing-01-use-std-unnested/src/main.rs b/listings/ch07-managing-growing-projects/no-listing-01-use-std-unnested/src/main.rs index 3a02c99633..24f728c6e0 100644 --- a/listings/ch07-managing-growing-projects/no-listing-01-use-std-unnested/src/main.rs +++ b/listings/ch07-managing-growing-projects/no-listing-01-use-std-unnested/src/main.rs @@ -1,4 +1,4 @@ -use rand::Rng; +use rand::RngExt; // ANCHOR: here // --snip-- use std::cmp::Ordering; @@ -9,7 +9,7 @@ use std::io; 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); println!("The secret number is: {secret_number}"); diff --git a/listings/ch09-error-handling/listing-09-13/Cargo.toml b/listings/ch09-error-handling/listing-09-13/Cargo.toml index 9f9c4acb96..29e22e9a67 100644 --- a/listings/ch09-error-handling/listing-09-13/Cargo.toml +++ b/listings/ch09-error-handling/listing-09-13/Cargo.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024" [dependencies] -rand = "0.8.5" +rand = "0.10.1" diff --git a/listings/ch09-error-handling/listing-09-13/src/main.rs b/listings/ch09-error-handling/listing-09-13/src/main.rs index 6c3e963450..ae0e68f26c 100644 --- a/listings/ch09-error-handling/listing-09-13/src/main.rs +++ b/listings/ch09-error-handling/listing-09-13/src/main.rs @@ -1,5 +1,5 @@ use guessing_game::Guess; -use rand::Rng; +use rand::RngExt; use std::cmp::Ordering; use std::io; @@ -8,7 +8,7 @@ mod guessing_game; 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."); diff --git a/listings/ch09-error-handling/no-listing-09-guess-out-of-range/Cargo.toml b/listings/ch09-error-handling/no-listing-09-guess-out-of-range/Cargo.toml index 9f9c4acb96..29e22e9a67 100644 --- a/listings/ch09-error-handling/no-listing-09-guess-out-of-range/Cargo.toml +++ b/listings/ch09-error-handling/no-listing-09-guess-out-of-range/Cargo.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024" [dependencies] -rand = "0.8.5" +rand = "0.10.1" diff --git a/listings/ch09-error-handling/no-listing-09-guess-out-of-range/src/main.rs b/listings/ch09-error-handling/no-listing-09-guess-out-of-range/src/main.rs index fc22cbc5ef..b1d730caf3 100644 --- a/listings/ch09-error-handling/no-listing-09-guess-out-of-range/src/main.rs +++ b/listings/ch09-error-handling/no-listing-09-guess-out-of-range/src/main.rs @@ -1,11 +1,11 @@ -use rand::Rng; +use rand::RngExt; use std::cmp::Ordering; use std::io; 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); // ANCHOR: here loop { diff --git a/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/add_one/Cargo.toml b/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/add_one/Cargo.toml index d399d96e7b..5db60e1166 100644 --- a/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/add_one/Cargo.toml +++ b/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/add_one/Cargo.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024" [dependencies] -rand = "0.8.5" +rand = "0.10.1" diff --git a/listings/ch14-more-about-cargo/output-only-03-use-rand/add/add_one/Cargo.toml b/listings/ch14-more-about-cargo/output-only-03-use-rand/add/add_one/Cargo.toml index d399d96e7b..5db60e1166 100644 --- a/listings/ch14-more-about-cargo/output-only-03-use-rand/add/add_one/Cargo.toml +++ b/listings/ch14-more-about-cargo/output-only-03-use-rand/add/add_one/Cargo.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024" [dependencies] -rand = "0.8.5" +rand = "0.10.1" diff --git a/src/ch01-01-installation.md b/src/ch01-01-installation.md index 39d8371a6c..7f6b919b40 100644 --- a/src/ch01-01-installation.md +++ b/src/ch01-01-installation.md @@ -161,7 +161,7 @@ what `cargo` is and what each of these commands does in detail later.) ```console $ cargo new get-dependencies $ cd get-dependencies -$ cargo add rand@0.8.5 trpl@0.2.0 +$ cargo add rand@0.10.1 trpl@0.2.0 ``` This will cache the downloads for these packages so you will not need to diff --git a/src/ch02-00-guessing-game-tutorial.md b/src/ch02-00-guessing-game-tutorial.md index 3c590a1994..60e066ef40 100644 --- a/src/ch02-00-guessing-game-tutorial.md +++ b/src/ch02-00-guessing-game-tutorial.md @@ -359,15 +359,15 @@ In the _Cargo.toml_ file, everything that follows a header is part of that section that continues until another section starts. In `[dependencies]`, you tell Cargo which external crates your project depends on and which versions of those crates you require. In this case, we specify the `rand` crate with the -semantic version specifier `0.8.5`. Cargo understands [Semantic +semantic version specifier `0.10.1`. Cargo understands [Semantic Versioning][semver] (sometimes called _SemVer_), which is a -standard for writing version numbers. The specifier `0.8.5` is actually -shorthand for `^0.8.5`, which means any version that is at least 0.8.5 but -below 0.9.0. +standard for writing version numbers. The specifier `0.10.1` is actually +shorthand for `^0.10.1`, which means any version that is at least 0.10.1 but +below 0.11.0. Cargo considers these versions to have public APIs compatible with version -0.8.5, and this specification ensures that you’ll get the latest patch release -that will still compile with the code in this chapter. Any version 0.9.0 or +0.10.1, and this specification ensures that you’ll get the latest patch release +that will still compile with the code in this chapter. Any version 0.11.0 or greater is not guaranteed to have the same API as what the following examples use. @@ -386,7 +386,7 @@ cargo build --> $ cargo build Updating crates.io index Locking 15 packages to latest Rust 1.85.0 compatible versions - Adding rand v0.8.5 (available: v0.9.0) + Adding rand v0.10.1 (available: v0.11.0) Compiling proc-macro2 v1.0.93 Compiling unicode-ident v1.0.17 Compiling libc v0.2.170 @@ -400,7 +400,7 @@ $ cargo build Compiling zerocopy v0.7.35 Compiling ppv-lite86 v0.2.20 Compiling rand_chacha v0.3.1 - Compiling rand v0.8.5 + Compiling rand v0.10.1 Compiling guessing_game v0.1.0 (file:///projects/guessing_game) Finished `dev` profile [unoptimized + debuginfo] target(s) in 2.48s ``` @@ -455,7 +455,7 @@ reuse what it has already downloaded and compiled for those. Cargo has a mechanism that ensures that you can rebuild the same artifact every time you or anyone else builds your code: Cargo will use only the versions of the dependencies you specified until you indicate otherwise. For example, say -that next week version 0.8.6 of the `rand` crate comes out, and that version +that next week version 0.10.2 of the `rand` crate comes out, and that version contains an important bug fix, but it also contains a regression that will break your code. To handle this, Rust creates the _Cargo.lock_ file the first time you run `cargo build`, so we now have this in the _guessing_game_ @@ -467,7 +467,7 @@ _Cargo.lock_ file. When you build your project in the future, Cargo will see that the _Cargo.lock_ file exists and will use the versions specified there rather than doing all the work of figuring out versions again. This lets you have a reproducible build automatically. In other words, your project will -remain at 0.8.5 until you explicitly upgrade, thanks to the _Cargo.lock_ file. +remain at 0.10.1 until you explicitly upgrade, thanks to the _Cargo.lock_ file. Because the _Cargo.lock_ file is important for reproducible builds, it’s often checked into source control with the rest of the code in your project. @@ -477,8 +477,8 @@ When you _do_ want to update a crate, Cargo provides the command `update`, which will ignore the _Cargo.lock_ file and figure out all the latest versions that fit your specifications in _Cargo.toml_. Cargo will then write those versions to the _Cargo.lock_ file. Otherwise, by default, Cargo will only look -for versions greater than 0.8.5 and less than 0.9.0. If the `rand` crate has -released the two new versions 0.8.6 and 0.999.0, you would see the following if +for versions greater than 0.10.1 and less than 0.11.0. If the `rand` crate has +released the two new versions 0.10.2 and 0.999.0, you would see the following if you ran `cargo update`: $ cargo update Updating crates.io index Locking 1 package to latest Rust 1.85.0 compatible version - Updating rand v0.8.5 -> v0.8.6 (available: v0.999.0) + Updating rand v0.10.1 -> v0.10.2 (available: v0.999.0) ``` Cargo ignores the 0.999.0 release. At this point, you would also notice a change in your _Cargo.lock_ file noting that the version of the `rand` crate -you are now using is 0.8.6. To use `rand` version 0.999.0 or any version in the +you are now using is 0.10.2. To use `rand` version 0.999.0 or any version in the 0.999._x_ series, you’d have to update the _Cargo.toml_ file to look like this instead (don’t actually make this change because the following examples assume -you’re using `rand` 0.8): +you’re using `rand` 0.10): ```toml [dependencies] @@ -529,17 +529,17 @@ update _src/main.rs_, as shown in Listing 2-3. -First, we add the line `use rand::Rng;`. The `Rng` trait defines methods that +First, we add the line `use rand::RngExt;`. The `RngExt` trait defines methods that 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` -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 +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 `RngExt` +trait that we brought into scope with the `use rand::RngExt;` statement. The +`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. diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index 8397114f76..09dcd77fc3 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -193,8 +193,8 @@ make `rand` available to our project. Then, to bring `rand` definitions into the scope of our package, we added a `use` line starting with the name of the crate, `rand`, and listed the items we wanted to bring into scope. Recall that in [“Generating a Random -Number”][rand] in Chapter 2, we brought the `Rng` trait into -scope and called the `rand::thread_rng` function: +Number”][rand] in Chapter 2, we brought the `RngExt` trait into +scope and called the `rand::rng` function: ```rust,ignore {{#rustdoc_include ../listings/ch02-guessing-game-tutorial/listing-02-03/src/main.rs:ch07-04}} diff --git a/src/ch14-03-cargo-workspaces.md b/src/ch14-03-cargo-workspaces.md index ad47b8b7e3..709fe8459e 100644 --- a/src/ch14-03-cargo-workspaces.md +++ b/src/ch14-03-cargo-workspaces.md @@ -239,9 +239,9 @@ copy output below; the output updating script doesn't handle subdirectories in p ```console $ cargo build Updating crates.io index - Downloaded rand v0.8.5 + Downloaded rand v0.10.1 --snip-- - Compiling rand v0.8.5 + Compiling rand v0.10.1 Compiling add_one v0.1.0 (file:///projects/add/add_one) warning: unused import: `rand` --> add_one/src/lib.rs:1:5 From 5eec5453953402f94c8ed1745b03cd6cb07de884 Mon Sep 17 00:00:00 2001 From: Abhishek Shinde Date: Mon, 18 May 2026 20:08:03 +0530 Subject: [PATCH 2/2] Add RngExt to dictionary.txt to pass failing CI test. --- ci/dictionary.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/dictionary.txt b/ci/dictionary.txt index 92cb8e5096..565c934f13 100644 --- a/ci/dictionary.txt +++ b/ci/dictionary.txt @@ -460,6 +460,7 @@ retweet rewordings rint ripgrep +RngExt Rumbul runnable runtime