mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-26 09:08:14 +00:00
gst-play: use Fisher-Yates shuffle for shuffling the playlist
This commit is contained in:
parent
0340c7e1f8
commit
7e9d6720ca
1 changed files with 3 additions and 3 deletions
|
@ -817,9 +817,9 @@ shuffle_uris (gchar ** uris, guint num)
|
||||||
if (num < 2)
|
if (num < 2)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (i = 0; i < num; i++) {
|
for (i = num - 1; i >= 1; i--) {
|
||||||
/* gets equally distributed random number in 0..num-1 [0;num[ */
|
/* +1 because number returned will be in range [a;b[ so excl. stop */
|
||||||
j = g_random_int_range (0, num);
|
j = g_random_int_range (0, i + 1);
|
||||||
tmp = uris[j];
|
tmp = uris[j];
|
||||||
uris[j] = uris[i];
|
uris[j] = uris[i];
|
||||||
uris[i] = tmp;
|
uris[i] = tmp;
|
||||||
|
|
Loading…
Reference in a new issue