0

I'm just getting started in rust and I want to use the rand dependency, so I added it using cargo add rand to the Cargo.toml file used by the project.

Here is the code (at the moment a short algorithm to generate a random array of any size):

use rand;
const SIZE: usize = 100;
fn main(){
    let array = generate_array();
println!("{:?}", array);
}

fn generate_array() -> [i16; SIZE]{
    let mut array = [0; SIZE];
    let mut i: usize = 0;
    while i < SIZE{
        array[i] = 2;
        i += 1;
    }
    array
}

And here is the Cargo.toml:

[package]
name = "sorting_algorithms"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.5"

Every time I try to run the script I get this error message (I'm using VS code):

error[E0432]: unresolved import `rand`
 --> array_generator.rs:1:5
  |
1 | use rand;
  |     ^^^^ no `rand` in the root

error: aborting due to previous error
Anders Evensen
  • 579
  • 5
  • 15
kokis
  • 1
  • 1

0 Answers0