So I was trying to generate a sample of 5 numbers with:
use rand::{thread_rng, seq};
use std::time::SystemTime;
fn main(){
let mut rng = thread_rng();
let mut sample = seq::index::sample(&mut rng, 50, 5);
}
But when I try to sort it with:
sample.sort();
It gives me the following error:
error[E0599]: no method named
sort
found for typerand::seq::index::IndexVec
in the current scope --> src/main.rs:12:16
How can I sort a random sample of numbers?
Bonus question: Is there a way to sample in a certain vector of elements? For example choose 3 numbers in [1,2,4,6,7,11,22,33]?
Aucun commentaire:
Enregistrer un commentaire