diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-09-05 16:27:00 +0200 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-09-05 16:27:00 +0200 |
| commit | 5dcc8275e53ee78ac738640e6359070362ae6cf6 (patch) | |
| tree | 00d82fc914fa1b6985cdccd964a3694beb545fdc | |
| parent | pkgs/mpppom: Use the new pre-cache direnv system (diff) | |
| download | nixos-config-5dcc8275e53ee78ac738640e6359070362ae6cf6.zip | |
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.
| -rw-r--r-- | pkgs/by-name/mp/mpdpopm/src/dj/algorithms.rs | 12 |
1 files changed, 8 insertions, 4 deletions
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::<Vec<_>>(); - let neutral = sorted_tracks.drain(..len).collect::<Vec<_>>(); - let positive = sorted_tracks; + let mut negative = sorted_tracks.drain(..len).collect::<Vec<_>>(); + let mut neutral = sorted_tracks.drain(..len).collect::<Vec<_>>(); + let mut positive = sorted_tracks; + + negative.shuffle(&mut rng); + neutral.shuffle(&mut rng); + positive.shuffle(&mut rng); assert_eq!(negative.len(), neutral.len()); |
