Bug 102238

Summary: Random play is not random
Product: [Applications] juk Reporter: David Johnson <david>
Component: generalAssignee: Scott Wheeler <wheeler>
Status: RESOLVED FIXED    
Severity: normal CC: Marcin.Kasperski
Priority: NOR    
Version: 2.2   
Target Milestone: ---   
Platform: FreeBSD Ports   
OS: FreeBSD   
Latest Commit: Version Fixed In:
Attachments: Patch to call srandomdev before random() functions

Description David Johnson 2005-03-23 03:39:36 UTC
Version:           2.2 (using KDE KDE 3.4.0)
Installed from:    FreeBSD Ports
Compiler:          gcc 3.4.2 
OS:                FreeBSD

When Player->Random Play->Use Random Play is selected, the results are not random. When I click on collection the same song is always selected. Subsequent songs are always in the same sequence. I get the exact same sequence of songs everytime JuK is run. The behavior is as if it uses the same seed everytime for a bad random number generator. There were no problems with the prior versions.

Partial contents of jukrc are:

[Player]
LoopPlaylist=true
RandomPlay=Normal
Volume=100

[Playlists]
CollectionListSortAscending=true
CollectionListSortColumn=1
DirectoryList=/alt/share/music
ImportPlaylists=false
showUpcoming=false

[Settings]
DockInSystemTray=true
DockOnClose=true
MediaSystem=1
ShowSplashScreen=true
StartDocked=false
TrackPopup=false
Comment 1 Kevin Dorne 2005-03-23 22:38:13 UTC
This seems to happen with random by album as well.  not sure if it's just in the newest version, as I never used random by album before.  The random by track used to seem random, though.
Comment 2 Michael Pyne 2005-05-18 21:58:50 UTC
*** Bug 105900 has been marked as a duplicate of this bug. ***
Comment 3 Kevin Dorne 2005-07-04 06:00:41 UTC
Created attachment 11672 [details]
Patch to call srandomdev before random() functions

This will only work on *BSD systems, AFAIK
Comment 4 Michael Pyne 2005-08-18 04:23:31 UTC
SVN commit 450391 by mpyne:

Fix bug 102238 (Random play is not random between starts) in KDE 3.5, by
using KApplication::random() (which will always initialize a random seed)
instead of the C library (which may or may not initialize a random seed).

CCBUG:102238


 M  +4 -5      tracksequenceiterator.cpp  


--- branches/KDE/3.5/kdemultimedia/juk/tracksequenceiterator.cpp #450390:450391
@@ -14,10 +14,9 @@
  ***************************************************************************/
 
 #include <kaction.h>
+#include <kapplication.h>
 #include <kdebug.h>
 
-#include <stdlib.h>
-
 #include "tracksequenceiterator.h"
 #include "playlist.h"
 #include "actioncollection.h"
@@ -89,7 +88,7 @@
 
         if(albumRandom) {
             if(m_albumSearch.isNull() || m_albumSearch.matchedItems().isEmpty()) {
-                item = m_randomItems[::random() % m_randomItems.count()];
+                item = m_randomItems[KApplication::random() % m_randomItems.count()];
                 initAlbumSearch(item);
             }
 
@@ -115,7 +114,7 @@
             }
         }
         else
-            item = m_randomItems[::random() % m_randomItems.count()];
+            item = m_randomItems[KApplication::random() % m_randomItems.count()];
 
         setCurrent(item);
         m_randomItems.remove(item);
@@ -156,7 +155,7 @@
 
         PlaylistItem *newItem = 0;
         if(!items.isEmpty())
-            newItem = items[::random() % items.count()];
+            newItem = items[KApplication::random() % items.count()];
 
         setCurrent(newItem);
         refillRandomList();
Comment 5 Michael Pyne 2005-08-18 04:25:18 UTC
SVN commit 450395 by mpyne:

Backport fix for bug 102238 (Random play is not random between starts) to KDE
3.4.

BUG:102238


 M  +4 -5      tracksequenceiterator.cpp  


--- branches/KDE/3.4/kdemultimedia/juk/tracksequenceiterator.cpp #450394:450395
@@ -14,10 +14,9 @@
  ***************************************************************************/
 
 #include <kaction.h>
+#include <kapplication.h>
 #include <kdebug.h>
 
-#include <stdlib.h>
-
 #include "tracksequenceiterator.h"
 #include "playlist.h"
 #include "actioncollection.h"
@@ -81,7 +80,7 @@
 
         if(albumRandom) {
             if(m_albumSearch.isNull() || m_albumSearch.matchedItems().isEmpty()) {
-                item = m_randomItems[::random() % m_randomItems.count()];
+                item = m_randomItems[KApplication::random() % m_randomItems.count()];
                 initAlbumSearch(item);
             }
 
@@ -107,7 +106,7 @@
             }
         }
         else
-            item = m_randomItems[::random() % m_randomItems.count()];
+            item = m_randomItems[KApplication::random() % m_randomItems.count()];
 
         setCurrent(item);
         m_randomItems.remove(item);
@@ -148,7 +147,7 @@
 
         PlaylistItem *newItem = 0;
         if(!items.isEmpty())
-            newItem = items[::random() % items.count()];
+            newItem = items[KApplication::random() % items.count()];
 
         setCurrent(newItem);
         refillRandomList();