summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/playlist.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/common/playlist.c b/common/playlist.c
index 4c003c5f21..b2b297d671 100644
--- a/common/playlist.c
+++ b/common/playlist.c
@@ -169,11 +169,9 @@ void playlist_shuffle(struct playlist *pl)
arr[n] = pl->first;
playlist_unlink(pl, pl->first);
}
- for (int n = 0; n < count; n++) {
- int other = (int)((double)(count) * rand() / (RAND_MAX + 1.0));
- struct playlist_entry *tmp = arr[n];
- arr[n] = arr[other];
- arr[other] = tmp;
+ for (int n = 0; n < count - 1; n++) {
+ int j = (int)((double)(count - n) * rand() / (RAND_MAX + 1.0));
+ MPSWAP(struct playlist_entry *, arr[n], arr[n + j]);
}
for (int n = 0; n < count; n++)
playlist_add(pl, arr[n]);