[vlc-commits] commit: playlist: randomize in a thread-safe manner ( Rémi Denis-Courmont )
git at videolan.org
git at videolan.org
Sat Mar 6 11:30:22 CET 2010
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Mar 6 12:20:41 2010 +0200| [8d00d8b7069d5b8d1090708976334cc31849fa50] | committer: Rémi Denis-Courmont
playlist: randomize in a thread-safe manner
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8d00d8b7069d5b8d1090708976334cc31849fa50
---
src/playlist/sort.c | 3 ++-
src/playlist/thread.c | 6 +++---
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/src/playlist/sort.c b/src/playlist/sort.c
index 7c82606..e125b0d 100644
--- a/src/playlist/sort.c
+++ b/src/playlist/sort.c
@@ -27,6 +27,7 @@
#endif
#include <vlc_common.h>
+#include <vlc_rand.h>
#define VLC_INTERNAL_PLAYLIST_SORT_FUNCTIONS
#include "vlc_playlist.h"
#include "playlist_internal.h"
@@ -146,7 +147,7 @@ void playlist_ItemArraySort( unsigned i_items, playlist_item_t **pp_items,
for( i_position = i_items - 1; i_position > 0; i_position-- )
{
- i_new = rand() % (i_position+1);
+ i_new = ((unsigned)vlc_mrand48()) % (i_position+1);
p_temp = pp_items[i_position];
pp_items[i_position] = pp_items[i_new];
pp_items[i_new] = p_temp;
diff --git a/src/playlist/thread.c b/src/playlist/thread.c
index 25292e6..4cbd2a3 100644
--- a/src/playlist/thread.c
+++ b/src/playlist/thread.c
@@ -32,6 +32,7 @@
#include <vlc_input.h>
#include <vlc_interface.h>
#include <vlc_playlist.h>
+#include <vlc_rand.h>
#include "stream_output/stream_output.h"
#include "playlist_internal.h"
@@ -189,10 +190,9 @@ static void ResetCurrentlyPlaying( playlist_t *p_playlist,
if( var_GetBool( p_playlist, "random" ) )
{
/* Shuffle the array */
- srand( (unsigned int)mdate() );
- for( int j = p_playlist->current.i_size - 1; j > 0; j-- )
+ for( unsigned j = p_playlist->current.i_size - 1; j > 0; j-- )
{
- int i = rand() % (j+1); /* between 0 and j */
+ unsigned i = ((unsigned)vlc_mrand48()) % (j+1); /* between 0 and j */
playlist_item_t *p_tmp;
/* swap the two items */
p_tmp = ARRAY_VAL(p_playlist->current, i);
More information about the vlc-commits
mailing list