"undeclared type or module rand" error

  |
3 | use rand::Rng;
  |     ^^^^ use of undeclared type or module `rand`

error[E0433]: failed to resolve: use of undeclared type or module `rand`
 --> src\main.rs:8:25
  |
8 |     let secret_number = rand::thread_rng().gen_range(1, 101);
  |                         ^^^^ use of undeclared type or module `rand`

Have you specified the rand crate as dependency? If yes, are you on edition 2015 or 2018? If the former, you also need to do extern crate.

1 Like

thanks buddy

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.