]> git.sesse.net Git - vlc/commitdiff
playlist: use Fisher-Yater shuffle instead naive when randomising playlist
authorIlkka Ollakka <ileoo@videolan.org>
Tue, 15 Sep 2009 07:41:23 +0000 (10:41 +0300)
committerIlkka Ollakka <ileoo@videolan.org>
Tue, 15 Sep 2009 07:41:23 +0000 (10:41 +0300)
src/playlist/sort.c

index af238c0b7a9fc229f7fec85f49ad6321c973c3bf..95abbbea364dc202688805fd980a93684b499f2b 100644 (file)
@@ -141,16 +141,12 @@ void playlist_ItemArraySort( unsigned i_items, playlist_item_t **pp_items,
     else /* Randomise */
     {
         unsigned i_position;
+        unsigned i_new;
         playlist_item_t *p_temp;
 
-        for( i_position = 0; i_position < i_items ; i_position++ )
+        for( i_position = i_items - 1; i_position > 0; i_position-- )
         {
-            int i_new;
-
-            if( i_items > 1 )
-                i_new = rand() % (i_items - 1);
-            else
-                i_new = 0;
+            i_new = rand() % i_position;
             p_temp = pp_items[i_position];
             pp_items[i_position] = pp_items[i_new];
             pp_items[i_new] = p_temp;