about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-01-31 16:45:29 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-01-31 16:45:29 +0100
commit1ae35c0d375642f9b6d3c228058e8666b95450e4 (patch)
tree289ed547bce75d0f268dd11f73002df965963ee3
parentpkgs/mpdpopm: Actually report, which kind of track we added (diff)
downloadnixos-config-1ae35c0d375642f9b6d3c228058e8666b95450e4.zip
pkgs/mpdpopm: Shuffle `positive`, `neutral` and `negative` pl before use
Diffstat (limited to '')
-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),