From c2b6f4db5b8efb0957776273b010b8655fabf73b Mon Sep 17 00:00:00 2001
From: "a.stevan" <antoine.stevan@isae-supaero.fr>
Date: Wed, 29 May 2024 17:06:51 +0200
Subject: [PATCH] use shuffle again...

---
 bins/inbreeding/src/random.rs | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/bins/inbreeding/src/random.rs b/bins/inbreeding/src/random.rs
index 8593049f..d5cb9276 100644
--- a/bins/inbreeding/src/random.rs
+++ b/bins/inbreeding/src/random.rs
@@ -1,6 +1,7 @@
-use rand::{Rng, RngCore};
+use rand::{seq::SliceRandom, Rng, RngCore};
 use std::collections::HashSet;
 
+#[allow(dead_code)]
 fn draw_unique_indices(n: usize, vec_len: usize, rng: &mut impl RngCore) -> HashSet<usize> {
     let mut indices = HashSet::new();
 
@@ -17,9 +18,8 @@ pub(super) fn draw_unique_elements<T: Clone>(
     n: usize,
     rng: &mut impl RngCore,
 ) -> Vec<T> {
-    let mut res = vec![];
-    for i in draw_unique_indices(n, things.len(), rng) {
-        res.push(things[i].clone());
-    }
-    res
+    let mut things = things.to_vec();
+    things.shuffle(rng);
+
+    things.iter().take(n).cloned().collect()
 }
-- 
GitLab