fix(player): Uniform shuffle
Replaces the current naive solution with Fisher-Yates
This commit is contained in:
parent
9e55593d79
commit
1f13e34249
1 changed files with 4 additions and 1 deletions
|
|
@ -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];
|
||||
|
|
|
|||
Loading…
Reference in a new issue