From 5dcc8275e53ee78ac738640e6359070362ae6cf6 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Sat, 5 Sep 2026 16:27:00 +0200 Subject: pkgs/mpppom/dj: Shuffle the neg/neu/pos vectors Otherwise, every start would start with the same songs again, only changing if songs get removed from neg or neu. This is obviously not ideal, because we are now no longer honouring high weight factors (as the pos vector gets shuffled). But save a complete rewrite of the algorithm I don't really see a better approach. --- pkgs/by-name/mp/mpdpopm/src/dj/algorithms.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'pkgs/by-name') diff --git a/pkgs/by-name/mp/mpdpopm/src/dj/algorithms.rs b/pkgs/by-name/mp/mpdpopm/src/dj/algorithms.rs index 3587df93..0004fd17 100644 --- a/pkgs/by-name/mp/mpdpopm/src/dj/algorithms.rs +++ b/pkgs/by-name/mp/mpdpopm/src/dj/algorithms.rs @@ -4,7 +4,7 @@ use std::{ }; use anyhow::{Context, Result}; -use rand::{RngExt, distr}; +use rand::{RngExt, distr, seq::SliceRandom}; use tracing::info; use crate::{clients::Client, storage}; @@ -115,9 +115,13 @@ impl Algorithm for Discovery { // We split the tracks into three thirds, so that we can also force a pick from e.g. // the lower third (the negative ones). - let negative = sorted_tracks.drain(..len).collect::>(); - let neutral = sorted_tracks.drain(..len).collect::>(); - let positive = sorted_tracks; + let mut negative = sorted_tracks.drain(..len).collect::>(); + let mut neutral = sorted_tracks.drain(..len).collect::>(); + let mut positive = sorted_tracks; + + negative.shuffle(&mut rng); + neutral.shuffle(&mut rng); + positive.shuffle(&mut rng); assert_eq!(negative.len(), neutral.len()); -- cgit v1.3.1