diff options
author | Max Kellermann <max@duempel.org> | 2009-01-13 21:25:19 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-01-13 23:10:34 +0100 |
commit | 823ea562421449dabfcf3afc621a211db2c40d3d (patch) | |
tree | e0cc1d02dc1101560151be4817a5693d808efbae /src/playlist.c | |
parent | f8a94fbda3421634896cbb950bc986db32b24ec9 (diff) | |
download | mpd-823ea562421449dabfcf3afc621a211db2c40d3d.tar.gz mpd-823ea562421449dabfcf3afc621a211db2c40d3d.tar.xz mpd-823ea562421449dabfcf3afc621a211db2c40d3d.zip |
playlist: implement Fisher-Yates shuffle properly
MPD's shuffling algorithm was not implemented well: it considers songs
which were already swapped, making it somewhat non-random.
Fix the Fisher-Yates shuffle algorithm by passing the proper bounds to
the PRNG.
Diffstat (limited to 'src/playlist.c')
-rw-r--r-- | src/playlist.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/playlist.c b/src/playlist.c index 621947544..96eff0a6f 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -1097,7 +1097,7 @@ static void randomizeOrder(int start, int end) clearPlayerQueue(); for (i = start; i <= end; i++) { - ri = g_rand_int_range(g_rand, start, end + 1); + ri = g_rand_int_range(g_rand, i, end + 1); if (ri == playlist.current) playlist.current = i; else if (i == playlist.current) @@ -1180,7 +1180,7 @@ void shufflePlaylist(void) } /* shuffle the rest of the list */ for (; i < playlist.length; i++) { - ri = g_rand_int_range(g_rand, 1, playlist.length); + ri = g_rand_int_range(g_rand, i, playlist.length); swapSongs(i, ri); } |