[MPlayer-dev-eng] [PATCH] Call srand() for proper rand() function

Krister Lagerstrom krister at kmlager.com
Sat Jan 11 08:06:58 CET 2003


When using "mplayer -shuffle *.mp3" with the latest CVS, the files are
always played in the same order. This is a bug IMHO.

This is because the random generator used by playtree.c (rand()) is
always initialized with the same seed since srand() is usually not
called before rand() is used in playtree.c.

The following patch adds a call to srand() with the current time at the
start of main(). It makees "-shuffle" to works as expected.

		/ Krister

-------------- next part --------------
Index: mplayer.c
===================================================================
RCS file: /cvsroot/mplayer/main/mplayer.c,v
retrieving revision 1.647
diff -u -u -r1.647 mplayer.c
--- mplayer.c	6 Jan 2003 12:27:39 -0000	1.647
+++ mplayer.c	11 Jan 2003 06:47:56 -0000
@@ -631,6 +631,8 @@
 
 int gui_no_filename=0;
 
+  srand((int) time(NULL)); 
+
   mp_msg_init();
   mp_msg_set_level(MSGL_STATUS);
 



More information about the MPlayer-dev-eng mailing list