rust-lang-nursery / rust-cookbook

https://rust-lang-nursery.github.io/rust-cookbook
Creative Commons Zero v1.0 Universal
2.25k stars 284 forks source link

Randomness gen_range example broken #622

Closed oakmanjacob closed 3 years ago

oakmanjacob commented 3 years ago

Under the "Generate random numbers within a range" section the rng.gen_range function is called with two parameters instead of submitting one range as is implemented in rand v0.8.0.

The lines:

println!("Integer: {}", rng.gen_range(0, 10));
println!("Float: {}", rng.gen_range(0.0, 10.0));

should be:

println!("Integer: {}", rng.gen_range(0..10));
println!("Float: {}", rng.gen_range(0.0..10.0));

The code compiling and running successfully on the website indicates that while this code is marked rand v0.8.0 it must be running rand v0.7.3 or before.