fix(player): Uniform shuffle

Replaces the current naive solution with Fisher-Yates
This commit is contained in:
Sietse 2026-02-21 20:53:42 +01:00 committed by GitHub
parent 9e55593d79
commit 1f13e34249
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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];