My Fix for the lack of randomness offered via the built-in Shuffle feature of ROON

OK fellow ROON Linux/Ubuntu Users. This ones for you. I would chalk this up as a nice rainy day project if you feel inclined enough to give it a try.

So after losing faith waiting for a permanent fix to the above mentioned issue that’s been around since version 1 (basically) I set out to try and come up with a fix of my own. This goal has been accomplished 100% for my purposes; maybe it will be good others also?

Summary of Goal:

I want to be able to select a Playlist (That I created) within ROON and “Shuffle” just that specific Playlist. This Playlist is typically based on the contents of some Child Sub-Folder living below the Primary ROON Music folder on my NAS. In many cases, this Playlist also consists of only one specific Genre of Music.

Most importantly here, I want those tracks found within that Playlist to be “Shuffled” in such a way that I should never find myself saying “Hey, didn’t I just hear these tracks last time I played this Playlist yesterday, or the day before, or the day before that…etc?”. I mean, some of these Playlists are very large so there is no reason\excuse to be hearing the same tracks again and again. If the “Shuffle” function was truly Random this would not be an issue. Clearly, it is not Random at all. I believe the Shuffle mechanism instead uses “intelligence” that thinks those songs most often played are also the same songs someone wants to hear more often. Of course there is a problem with that when the Shuffle feature keeps picking the same crap every time thus skewing the results of any process relying of this form of decision making.

Anyway…enough with the Rant and onto the solution. Below is a Highlevel List of what I did for those wanting to get a general idea. I will follow up with specifics at the end.

  1. Create a Master PlayList of every track/album found within each music genre Sub-Folder found on my NAS. These folders are organized based on my definition of what Genre of Music lives inside it. Like So:

MUSIC…(ROON Parent Folder)…

   .............ROCK
                     ...........BOSTON
                                      ................THIRD STAGE
                                                              .......................Track #1
                                                              .......................Track #2

…METAL
…MELLOW
…BLUES

  1. These Master Playlists will be used as the “Source” for generating additional, very RANDOM, additional Playlists based on the Genre in question.

  2. Using the folder/genere/band/album/track data within each of these Master playlists above, assign each and every line a randomly generated up to 10 digit long numerical string.

  3. Using that randomly generated number string, sort the list of numbers from smallest to largest

  4. Pipe the output of that now random list of music tracks into a new .M3U Playlist

  5. Do all of this using only 2 scripts that are placed on the ROON Core server and are kicked off via a CRON Job that runs at some interval of your choosing.

  6. End Result…Depending on your choice/schedule frequency you will always have a Truly Random Playlist at your fingertips for any given Genre you care to listen to.

Continued in Next Post

1 Like

OK Folks,

Below I will paste some partially generalized code that would would need to edit to fit your purpose/usage.

This script is used to create the initial MASTER Genre Specific Playlist. You can add additional lines of code to cover each Sub-Folder you have under you Primary Music folder.

End result on this one will be a .M3U Playlist being placed directly under the Primary Music folder for each Genre you have listed in your code. If you run this particular script multiple times a day, you will always have an up to date list to work from, if you so choose.

roonsrv-getall-pl.sh

#!/bin/bash
cd /mnt/RoonStorage_xxxxxxx
find ROCK -type f \( -name '*.flac' -o -name '*.wav' -o -name '*.wma' -o -name '*.mp3' -o -name '*.m4a' -o -name '*.dsf' \)>>/mnt/RoonStorage_xxxxxx/ROCK-PL-MASTER.m3u

This next script uses the previously generated MASTER Playlist as its Source. At a very high level what it does is creates a Random Seed based on the Date/Time of the ROON Core at the time of execution. Then using that Seed it takes advantage of the Built-In Random number generation feature found within Linux/Ubuntu. This is doubled up to create a larger, up to 10 Digit number. A random number is then added to the beginning of each and every line found within the original MASTER Playlist .M3U file. The script then SORTS each line based on that random number and Pipes the results out to a new .M3U RANDOM Playlist. This new Playlist is also dumped at the ROOT of your ROON Music folder. You will see a “Sleep” line at the end in this example. That is for those who want to build onto this script like a did in my case. I found that a nice little pause was needed to prevent any errors since the computer in question needs to do some serious MATH for each Playlist. In my case, it takes about 1min for the whole script to finish. I’m dumping out about 10 Playlists in one go with upwards of 1TB of music content.

roonsrv-allnew-rand-pl.sh

RANDOM=`date +%N|sed s/...$//`
cat /mnt/RoonStorage_xxxxxxx/ROCK-PL-MASTER.m3u | while IFS= read -r f; do printf "%10d %s\n" "$RANDOM$RANDOM" "$f"; done | sort -n | cut -c12- >/mnt/RoonStorage_xxxxxxx/RAND-ROCK-PL.m3u
sleep 10

You will need to place these scripts on the ROON Core in some folder under the context of the ROOT User. I made a folder called “roonscripts” under /usr/bin

Also, the scripts will need to be made as executable to run

root@roonsrv:/usr/bin/roonscripts# ls -l
    total 8
    -rw-r--r-- 1 root root    0 Oct 10 16:02 cron.log
    -rwxr-xr-x 1 root root 3012 Oct 13 12:46 roonsrv-allnew-rand-pl.sh
    -rwxr-xr-x 1 root root 2261 Oct 13 11:58 roonsrv-getall-pl.sh

Last but not least, you will need to add new Cron Jobs to run the scrips. This will need to be done under the Root context/User again. Additionally, I found a need to add the path to the scripts to the PATH line in the CronTab before they would run.

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/bin/roonscripts 
# m h  dom mon dow   command
0  5  *  *  *  /usr/bin/roonscripts/roonsrv-allnew-rand-pl.sh >/dev/null 2>&1
0  3  *  *  5  /usr/bin/roonscripts/roonsrv-getall-pl.sh >/dev/null 2>&1

Give it a try and let me know how it goes or if you have any questions. I’ve been very brief here in an attempt to not make too large a wall of text. The expectation with this post is that most using Linux/Ubuntu will find there way or are already fairly familiar with some of these concepts. If you need more details please let me know

Thanks

For anyone interested in seeing what is happening to the Playlist in order for the Random Sort to work take a look at a snipet of output below. You will see at the beginning of each line the random number that was assigned to that line at the time of script execution. If chopped most of the output out of this example here but you get the idea

 24591 HEAVY-METAL/Rainbow/Long Live Rock 'n' Roll (Remastered)/07-Sensitive To Light.flac
 37479 HEAVY-METAL/Marilyn Manson/Marilyn Manson (1996) Antichrist Superstar/97 - Non-Musical Silence.wav
 58067 HEAVY-METAL/Rush/Chronicles/Rush - 08 - What You're Doing [live].flac
139246 HEAVY-METAL/Ozzy Osbourne/No Rest for the Wicked/04 Ozzy Osbourne - Breakin' All the Rules.wav
165234 HEAVY-METAL/Type O Negative/Bloody Kisses, Disc 1/Type O Negative - 13 - Blood & Fire.flac
176834 HEAVY-METAL/Van Halen/Diver Down -Studio Albums Disk 5/06-(Oh) Pretty Woman.wav
.
.
.
.
.
.
 621912937 HEAVY-METAL/Cult, The/The Cult (1985) Love/09 - She Sells Sanctuary.wav
 622310161 HEAVY-METAL/MCAULEY SCHENKER/Mc Auley Schenker Group (1989) Save Yourself/09 - This Is My Heart.wav
 622421114 HEAVY-METAL/Vixen/Vixen/10-Cruisin'.flac
 622422025 HEAVY-METAL/Metallica/Metallica/Metallica - 06 - Don't Tread on Me.flac
 622719094 HEAVY-METAL/Dio/Dream Evil/04 Dio - All the Fools Sailed Away.wav
 622910844 HEAVY-METAL/Cinderella/Long Cold Winter/08 Cinderella - Coming Home.wav
 622917951 HEAVY-METAL/Great White/Hooked/Great White - 04 - Can't Shake It.flac
 623232392 HEAVY-METAL/Iron Maiden/The Number of the Beast/08 Iron Maiden - Hallowed Be Thy Name.wav
 623516521 HEAVY-METAL/White Lion/Pride/07 White Lion - All You Need Is Rock N Roll.wav
.
.
.
.
.
.
.
.
3273025530 HEAVY-METAL/Tesla/Time's Makin' Changes; The Best Of Tesla/Tesla - 03 - Little Suzi.flac
3273515315 HEAVY-METAL/Dokken/Dokken - Dysfunctional/02 - Hole in My Head.wav
3273712236 HEAVY-METAL/Guns N Roses/Appetite for Destruction/07 Guns N' Roses - My Michelle.wav
3273912278 HEAVY-METAL/Ratt/Ratt - Ratt & Roll 8191/04 - Wanted Man.wav
3274720156 HEAVY-METAL/Winger/Winger/07-Time To Surrender.flac
3274811490 HEAVY-METAL/Metallica/Ride the Lightning/05 Trapped Under Ice.m4a
3274832340 HEAVY-METAL/Tool/Tool (2001) Lateralus/07 - Parabola.wav

Hi Chris,

I can’t replicate what you are seeing with Shuffle. When I hit the Shuffle play icon in a Playlist or the Shuffle icon in a Queue generated from a Playlist I get a different ordering each time that appears random to me.

There were some historical concerns about Shuffle, but SFAIK the folks in those threads had their concerns resolved in 1.4.

Would you mind stepping through what you are doing with some screenshots showing how Shuffle isn’t working for you ?

I appreciate that this is a departure from your thread about the scripts and will open a new thread about non-randomness if you would prefer.

Hello,

I was trying to come up with a way to show you what I am referring to but it appears my solution to do that is not possible.

The easiest way I could show you would be to dump the “History” Tab list into some .CSV or similar. I could then sort the data in the list. I am not seeing such an option to Export the file list so that is out. Ironically, I do see an option to export the actual Music files themselves which I have no interest in doing. Maybe this can be added into some next version?

Next up, I did find by using the “Focus” option I was able to show all tracks played within some period of time in History. I could then ADD another Column which would show the # of Plays for each track. This works fine…but again there is no way that I see to Export that list.

Lastly, I tried to instead just save the History list to a “Playlist”. That worked but this Playlist doesn’t appear anywhere I could find on the File system of the Core or the Remote. I assume its tucked away inside the DB somewhere out of prying fingers reach.

So…this leaves only screenshots (From that Focus output) that I could provide here which will only tell one pages worth of the story. I can do that if you feel its a worthwhile effort?

In summary though, the Shuffle option does indeed Shuffle just fine but my complaint is that it does appear to try very hard to ensure that the Shuffled list is very unique. Below is one specific example:

I have a Playlist with 150 songs in it categorized as “Mellow” music. Below is a screen shot taken that lists the Top 250 Songs played in the last 3 months. All the songs seen on this screenshot are from that “Mellow” Playlist made up of 150 Songs. you can see that there are songs with upwards of 30 Plays and I can say for sure there are some songs in that ORIG Playlist with Zero Plays still to their name.

My process, as an example, when Playing one of these Playlists is to select it from the List of Playlists and choose “Shuffle”. Nothing too fancy here. There are times though where I would choose “Shuffle”, hear a song that I know has been played too often so I will “Toggle” ON/OFF the Shuffle button again to initiate a Re-Shuffle if you will.

So this is just one small Playlist example. I have other Playlists with over 10K Songs in them. The behavior is similar as mentioned here in this small example.

Thanks for taking a look at my post

1 Like

Thanks Chris, that is helpful. Just one further screenshot if you don’t mind. Could you show the same playlist with “plays” ordered least first ?

I see you’ve described the way you select Shuffle to Play. How long a period would you think you listen to the Playlist each time ? A range is fine.

Apropos nothing much one of my favourite anecdotes about randomness was by Murray Gell-Mann. Upon arriving at Los Alamos he was provided with a book of random numbers, which every young nuclear physicist apparently needs. Inside the book there was an Erratum, correcting various entries, presumably on the basis that they were insufficiently random. Gell-Mann said he thought about that more than it probably warranted.

Hello Andybob,

Here is a screenshot that shows most of the original playlist example along with other files. Basically the lowest number of plays for the Playlist example in question starts at “11” and goes up from there. This screenshot happens to only show items with “12” plays.

Sticking to the example Playlist “MELLOW” which contains only 145 Tracks and has a listed Runtime of 12hrs I would say more times then not I would play that Playlist between 6-8hrs worth of it on Thursdays in one sitting. I would probably do this 2 times a month. There are of course times were it will be played for only an hour also but that is a rare occasion.

Oddly enough, I would say most of my playlist plays do not appear to be reflected in that “Focus” window when choosing Top 250 for past 3 months. Reason I say this is because 7-10 times I listen to music it is from my “HEAVY METAL” Playlist which is 15,000 tracks deep and runs for many hours a week. I would say between 30-40hrs a week just for that one Playlist. But I don’t want to muddy the waters bringing up the “Focus” feature right now as its not a feature I really ever use except in the case of this thread.

Perhaps one of the greenhorns assigned with populating the random numbers in the book given to Mr Murray Gell-Mann forgot to add a dash of “Salt” before generating some of the flagged numbers. But then again, they didn’t have to deal with something as important as randomizing their music library :stuck_out_tongue_winking_eye:

1 Like

Playlist shuffle is not random - very irritating