Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to use rand 0.9 throughout #4254

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -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 @@ -8,7 +8,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 @@ -8,7 +8,7 @@ fn main() {
// 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}");

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 @@ -5,7 +5,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}");

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 @@ -5,7 +5,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);

loop {
println!("Please input your guess.");
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 @@ -5,7 +5,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}");

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 @@ -5,7 +5,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);

// ANCHOR: here
// --snip--
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 @@ -5,7 +5,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}");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2024"

[dependencies]
rand = "0.8.5"
rand = "0.9.0"
Original file line number Diff line number Diff line change
Expand Up @@ -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}");

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 @@ -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}");

Expand Down
2 changes: 1 addition & 1 deletion listings/ch09-error-handling/listing-09-13/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2024"

[dependencies]
rand = "0.8.5"
rand = "0.9.0"
2 changes: 1 addition & 1 deletion listings/ch09-error-handling/listing-09-13/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,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);

loop {
println!("Please input your guess.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2024"

[dependencies]
rand = "0.8.5"
rand = "0.9.0"
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,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);

// ANCHOR: here
loop {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2024"

[dependencies]
rand = "0.8.5"
rand = "0.9.0"
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2024"

[dependencies]
rand = "0.8.5"
rand = "0.9.0"
2 changes: 1 addition & 1 deletion nostarch/appendix.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ value in each field in the order in which the fields appear in the struct
definition. When derived on enums, variants of the enum declared earlier in the
enum definition are considered less than the variants listed later.

The `PartialOrd` trait is required, for example, for the `gen_range` method
The `PartialOrd` trait is required, for example, for the `random_range` method
from the `rand` crate that generates a random value in the range specified by a
range expression.

Expand Down
2 changes: 1 addition & 1 deletion nostarch/appendix_c.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ value in each field in the order in which the fields appear in the struct
definition. When derived on enums, variants of the enum declared earlier in the
enum definition are considered less than the variants listed later.

The `PartialOrd` trait is required, for example, for the `gen_range` method
The `PartialOrd` trait is required, for example, for the `random_range` method
from the `rand` crate that generates a random value in the range specified by a
range expression.

Expand Down
12 changes: 6 additions & 6 deletions nostarch/chapter02.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ Filename: Cargo.toml

```
[dependencies]
rand = "0.8.5"
rand = "0.9.0"
```

In the *Cargo.toml* file, everything that follows a header is part of that
Expand Down Expand Up @@ -522,7 +522,7 @@ use std::io;
fn main() {
println!("Guess the number!");

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

3 println!("The secret number is: {secret_number}");

Expand All @@ -545,12 +545,12 @@ 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 [2], 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.
Expand Down Expand Up @@ -960,7 +960,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);

loop {
println!("Please input your guess.");
Expand Down
6 changes: 3 additions & 3 deletions nostarch/chapter07.md
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ added this line to *Cargo.toml*:
Filename: Cargo.toml

```
rand = "0.8.5"
rand = "0.9.0"
```

Adding `rand` as a dependency in *Cargo.toml* tells Cargo to download the
Expand All @@ -1040,13 +1040,13 @@ 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 the “Generating a Random
Number” section in Chapter 2, we brought the `Rng` trait
into scope and called the `rand::thread_rng` function:
into scope and called the `rand::rng` function:

```
use rand::Rng;

fn main() {
let secret_number = rand::thread_rng().gen_range(1..=100);
let secret_number = rand::rng().random_range(1..=100);
}
```

Expand Down
2 changes: 1 addition & 1 deletion nostarch/chapter14.md
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ Filename: add_one/Cargo.toml

```
[dependencies]
rand = "0.8.5"
rand = "0.9.0"
```

We can now add `use rand;` to the *add_one/src/lib.rs* file, and building the
Expand Down
2 changes: 1 addition & 1 deletion src/appendix-03-derivable-traits.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ value in each field in the order in which the fields appear in the struct
definition. When derived on enums, variants of the enum declared earlier in the
enum definition are considered less than the variants listed later.

The `PartialOrd` trait is required, for example, for the `gen_range` method
The `PartialOrd` trait is required, for example, for the `random_range` method
from the `rand` crate that generates a random value in the range specified by a
range expression.

Expand Down
6 changes: 3 additions & 3 deletions src/ch02-00-guessing-game-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -525,12 +525,12 @@ 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ 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]<!-- ignore --> in Chapter 2, we brought the `Rng` trait into
scope and called the `rand::thread_rng` function:
scope and called the `rand::rng` function:

```rust,ignore
{{#rustdoc_include ../listings/ch02-guessing-game-tutorial/listing-02-03/src/main.rs:ch07-04}}
Expand Down