What I want is to have one helper function to return a random vector:
let i32_vec = gen_random_vec<i32>(100);
let f32_vec = gen_random_vec<f32>(10);
// etc
I wrote the following code but it can't make the compiler happy
use rand::distributions::{Distribution};
use rand::Rng;
pub fn gen_random_vec<T>(size: usize) -> Vec<T>
where
T: Distribution,
{
let mut res: Vec<T> = Vec::with_capacity(size);
let mut rng = rand::thread_rng();
for i in 0..size {
let x : T = rng.gen();
res.push(x);
}
res
}
ref: https://rust-random.github.io/rand/rand/trait.Rng.html
Would be appreciate if somebody can help me complete the helper function.