I have a vector where the element is a (String, String). How can I randomly pick one of these elements?
(String, String)
You want the rand crate, specifically the choose method.
rand
choose
use rand::seq::SliceRandom; // 0.7.2 fn main() { let vs = vec![0, 1, 2, 3, 4]; println!("{:?}", vs.choose(&mut rand::thread_rng())); }
1.4m articles
1.4m replys
5 comments
57.0k users