
The art of shuffling music - wfunction
http://keyj.emphy.de/balanced-shuffle/
======
wampus
I don't understand why the genre matters. Most of the problems with shuffle
play go away if you prune the songs you don't like out of your collection.
True randomness is fine if you follow a few basic principles:

1\. Don't repeat songs too soon. A record of the last 100 or so songs should
be enough and doesn't use much memory. If shuffling a short playlist or album,
don't repeat until they've all been played.

2\. Don't attempt to group similar sounding songs together. I've never seen an
algorithm succeed at this and it serves no aesthetic purpose. If I want to
maintain a mood, I'll create a playlist, select songs manually, or just hit
skip.

3\. Don't ignore new material. If I add, rename, or reorganize music I don't
want to do anything special for it to be included in the shuffle.

4\. Don't roll your own random algorithm. Ever since shuffle play was
introduced as a feature on CD players, there have been algorithms that will
play the same N out of X songs in a collection, clearly using some kind of
modulo-based function instead of a good quality PRNG. If your algorithm can
permanently exclude songs, it's broken.

None of this helps with songs that should remain part of a suite or have a
segue that is abruptly clipped, but some of those shouldn't be separate tracks
to begin with.

~~~
nemothekid
"True randomness" is at complete odds with points 1. and 2. If I flip a coin
10 times and get 10 heads, its still "truly random."

I think iPod's shuffle was originally truly random at first and it was changed
- I'm reminded of this thread from a while back -
[https://news.ycombinator.com/item?id=4301922](https://news.ycombinator.com/item?id=4301922)

------
dr4g0n
This has reminded me of my old MP3 player, I think it was made by Archos, that
had two shuffle modes: "shuffle" & "random".

The "random" mode would happily play songs from the playlist multiple times,
even directly after one another; "shuffle" on the other hand would never play
a song more than once per playlist. When I first got it I was fascinated by
this difference – I still wonder why they included both modes.

------
thaumasiotes
What I really want in a shuffling music player is for it to remember when I
jump to one song after listening to some other song, conclude "hey, I bet that
first song makes a good lead-in to that second song", and bias the shuffling
to use that transition more often. Is there a player that will do that?

~~~
danohuiginn
+1

What I want, and will probably never get round to implementing, is Markov
chain playlist generation. Collect play order from (high-quality, human-
generated) playlists, then use them to build Markov chains of tracks that tend
to be played after one another.

------
qnaal
iirc foobar2000 (maybe it was a plugin) had some pretty intense shuffle
tweaking- album-at-a-time, how far in your linear collection to jump (assuming
your genres were together), of course how long between plays of the same
song...

------
giancarlostoro
I've encountered a similar problem with the shuffle method in Clementine (I
love this music player) where it repeats a song not too long after having
played it. In the case of Clementine there is no "random playlist" generated,
the next song is randomly chosen, despite it having been played 3 songs ago,
or even 2 songs ago. So I've noticed shuffling on several software is quite a
pain. Interesting read, I wouldn't mind as much the issues in this article
since most of my playlists are of the same genre, although I do get the issue
of upbeat / lowbeat songs.

~~~
k-mcgrady
That sounds like a pretty basic bug not to catch in a shuffling function.
Sounds like it shuffles for ever and never reaches the end then? I haven't
heard of clementine before. What does it provide you that other music apps
don't?

~~~
liotier
> I haven't heard of clementine before. > What does it provide you that other
> music apps don't?

Love. All that sweet Amarok 1.4 UX, untainted by the 2.0 branch shark jumping.

The playlist management just feels right, but the killer feature for me is the
indexed library that provides instant searches - perfect for enthusiastically
digging into a large collection.

Although it is an entirely different concept, Amarok and later Clementine are
what convinced me to jump ship from the file explorer + Winamp-like combo that
used to be my sweet spot.

~~~
giancarlostoro
It was inspired by Amarok so that's to no surprise.

------
reddytowns
FWIW I hacked up a program over the years that I use to shuffle my music. It
works on unix based boxes with perl and mpv available. It does the following:

* Keeps track of songs already played, so songs heard recently won't be played as much as songs not played recently

* If Control-C is pressed while listening to a song, it will reduce the frequency the song is played

* If the song is listened through in its entirety, the frequency it will be played is increased

* Any new music just added will be given higher priority than old, already played stuff

* Songs from each directory are played more or less equally. So if you have 30 songs from the Beatles and 500 from Black Sabbath, you won't hear Black Sabbath 94% of the time.

* Keeps track of every time a song is played and whether it is liked or not, so if later you want to use this data for something else, you have it available.

You need to pass the songs to it's standard in, eg:

find /disc1/my_music -type f | the_player.pl

To stop listening, you need to hit Control-Z to stop it, and then kill the
process.

Here it is: [http://pastebin.com/N7vj1pSc](http://pastebin.com/N7vj1pSc)

------
markbnj
I appreciate the idea of "content-aware" shuffling, but I wish the author had
not stated that random shuffling "lacks fairness and uniform distribution." If
that is true then the shuffle isn't very random. People have enough trouble
with randomness and its characteristics.

~~~
thaumasiotes
> I wish the author had not stated that random shuffling "lacks fairness and
> uniform distribution." If that is true then the shuffle isn't very random.

I have no idea what you're trying to say here. The lack of uniform
distribution that results from random sampling is well known. The author even
specifically elaborates on exactly what he's referring to _in the text that
immediately follows your quote_.

Random numbers always clump. What people actually have in mind when they think
of "random selection" is almost always a sample that visits every part of the
space with roughly equal frequency ("uniform"). See e.g.
[http://en.wikipedia.org/wiki/Halton_sequence](http://en.wikipedia.org/wiki/Halton_sequence)
.

Uniform random selection is "fair" and "uniform" _before the selection
happens_. But not afterward. What this guy, and most music listeners, want is
selection that visits every song in a "fair" and "uniform" manner _after the
selection has happened_ \-- they care about what the result is, not whether
certain aspects of the result could have been predicted in advance.

~~~
rcxdude
'uniform distribution' is a specific term in statistics which means something
separate to what uniform colloquially means, and in discussions like this it's
important to distinguish carefully between the terms. (i.e. A uniform
distribution is unlikely to be perceived as 'uniform', as you say)

------
gbog
Another related problem is how to auto generate playlists. I tried it with
many acoustic metrics and found nothing working well for my taste. I want
something that plays my music the way a good generalist radio would play it.
Following a genre is the opposite of what I want: I would be happy to have
blues, metal, classic, rap, techno, all shuffled together, as long as there is
some cross genre conference between the tracks. Tried it and did not succeed
yet.

------
stevebmark
If you work at Spotify, please read this immediately!

~~~
jagheterfredrik
[https://labs.spotify.com/2014/02/28/how-to-shuffle-
songs/](https://labs.spotify.com/2014/02/28/how-to-shuffle-songs/)

~~~
stevebmark
Interesting. I have a very large playlist (1,000+ songs) and there are songs I
never hear and songs I hear frequently.

------
jinushaun
I made a 500 song playlist on Spotify for my drive across the U.S. and
discovered that their "shuffle" was actually random. Or if it was a shuffle
algorithm, it was a bad one. Whenever I stopped playing (e.g., stopped car for
fuel or food), it reshuffled instead of continuing where it left off. As a
result, I heard the same 100 songs on that trip.

