Possible error in Rust Lang Book using rand that I cannot solve


#1

So I’m trying to learn Rust via the book/documentation, and there’s a section where you must create a guessing game. I try to use the rand crate (I guess this is what you call it), however, the compiler says the name is unresolved, so I’m guessing maybe it either has a new name or something now. Regardless, even in the book’s own online compiler it throws an error and will not run. You can find it here https://doc.rust-lang.org/book/guessing-game.html, can someone tell how I should write this code now?

The error is thrown on this line:
let secret_number = rand::thread_rng().gen_range(1, 101);
^^^^^^^^^^^^^^^


#2

Did you skip this part?

Using external crates is where Cargo really shines. Before we can write
the code using rand, we need to modify our Cargo.toml. Open it up, and
add these few lines at the bottom:

[dependencies]

rand="0.3.0"

Nothing involving external crates from crates.io will work in the playpen, because the playpen doesn’t use Cargo.


#3

although it does work in the alternative playpen http://play.integer32.com/?gist=69fb8c453c0bfda4292875f27edf1a07 :slight_smile: