From 1f13e342496beabb97b7c01545c63334bc11c43a Mon Sep 17 00:00:00 2001 From: Sietse <144368086+Sietse2202@users.noreply.github.com> Date: Sat, 21 Feb 2026 20:53:42 +0100 Subject: [PATCH] fix(player): Uniform shuffle Replaces the current naive solution with Fisher-Yates --- js/player.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/js/player.js b/js/player.js index 1a4689b..2013471 100644 --- a/js/player.js +++ b/js/player.js @@ -681,7 +681,10 @@ export class Player { tracksToShuffle.splice(this.currentQueueIndex, 1); } - tracksToShuffle.sort(() => Math.random() - 0.5); + for (let i = tracksToShuffle.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [tracksToShuffle[i], tracksToShuffle[j]] = [tracksToShuffle[j], tracksToShuffle[i]]; + } if (currentTrack) { this.shuffledQueue = [currentTrack, ...tracksToShuffle];