[vlc-devel] commit: playlist: use Fisher-Yater shuffle instead naive when randomising playlist ( Ilkka Ollakka )
git version control
git at videolan.org
Tue Sep 15 09:49:02 CEST 2009
vlc | branch: master | Ilkka Ollakka <ileoo at videolan.org> | Tue Sep 15 10:41:23 2009 +0300| [d5f996ac94656a3de08a85f483aaaa3b293b287d] | committer: Ilkka Ollakka
playlist: use Fisher-Yater shuffle instead naive when randomising playlist
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d5f996ac94656a3de08a85f483aaaa3b293b287d
---
src/playlist/sort.c | 10 +++-------
1 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/src/playlist/sort.c b/src/playlist/sort.c
index af238c0..95abbbe 100644
--- a/src/playlist/sort.c
+++ b/src/playlist/sort.c
@@ -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;
More information about the vlc-devel
mailing list