about summary refs log tree commit diff stats
path: root/pkgs/by-name
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/by-name')
-rw-r--r--pkgs/by-name/mp/mpdpopm/src/dj/algorithms.rs19
1 files changed, 11 insertions, 8 deletions
diff --git a/pkgs/by-name/mp/mpdpopm/src/dj/algorithms.rs b/pkgs/by-name/mp/mpdpopm/src/dj/algorithms.rs
index 37c91470..5ddfc7cb 100644
--- a/pkgs/by-name/mp/mpdpopm/src/dj/algorithms.rs
+++ b/pkgs/by-name/mp/mpdpopm/src/dj/algorithms.rs
@@ -1,7 +1,7 @@
 use std::collections::HashSet;
 
 use anyhow::{Context, Result};
-use rand::{Rng, distr};
+use rand::{Rng, distr, seq::SliceRandom};
 use tracing::info;
 
 use crate::{clients::Client, storage};
@@ -60,6 +60,7 @@ impl Algorithm for Discovery {
             }};
         }
 
+        let mut rng = rand::rng();
         let (mut positive, mut neutral, mut negative) = {
             let tracks = {
                 let mut base = client
@@ -96,16 +97,18 @@ impl Algorithm for Discovery {
                 }
             }
 
+            // Avoid an inherit ordering, that might be returned by the `Client::get_all_songs()` function.
+            positive.shuffle(&mut rng);
+            neutral.shuffle(&mut rng);
+            negative.shuffle(&mut rng);
+
             (positive, neutral, negative)
         };
 
-        let pick = {
-            let mut rng = rand::rng();
-            rng.sample(
-                distr::weighted::WeightedIndex::new([0.65, 0.5, 0.2].iter())
-                    .expect("to be valid, as hardcoded"),
-            )
-        };
+        let pick = rng.sample(
+            distr::weighted::WeightedIndex::new([0.65, 0.5, 0.2].iter())
+                .expect("to be valid, as hardcoded"),
+        );
 
         let next = match pick {
             0 => take!(positive, neutral, negative),