by mattnewton · 2y ago · 0 comments
https://engineering.atspotify.com/2014/02/how-to-shuffle-son...
It a good read on understanding what people generally expect when they ask for a random stream of songs (or comics), and how you can meet that expectation by carefully engineering how you generate “random” lists.
This isn't just me, but all my friends too. We're all the time finding old songs we saved that have never once been played with shuffle, while it's played this one song 3 times in the same day.
Perhaps it doesn't work as well with large playlists? Me and my friends tend toward 1000+ songs in a playlist, but most other playlists I've found are rarely over 250 songs.
First of all, the core idea that Same Artist == Similar Song and Different Artist == Dissimilar Song is already flawed. There are just way, way more axes than that. Getting 4 slow songs in a row in a playlist of mixed slow & fast dance music is going to feel very bad for everyone.
They give each artist one single "random offset". If this is uniform over [start, end], then it would absolutely kill artists that show up a lot on your playlist, dramatically in favor of artists you have once or twice. If it's from [start, end/N] with N being the number of songs of that artist, it would be a little better, but it's still making the playlist behavior completely different at the start (where it's mostly completely random) from the middle/end (where it's "dithered"). If it's [start, end/M] with M being anything else, it's again dramatically favoring the artists with fewer songs on the playlist.
Instead, they could introduce a "ghost" song for each artist that gets shuffled in and then discarded (or possibly some small constant number of ghosts).
I think I would be happy with a weighted random selection. Take 2 (or K) random numbers in range [0.0,1.0] and multiply them together to get X. X will favor the low end of the [0.0,1.0] range. Now sort the playlist from least recently played to most recently played. Next song = playlist[round(X * (playlist.Length - 1))].
Something like that. Note that "least recently played" would be a persisted attribute, not something that gets discarded in each shuffle "session". And not even local to this playlist -- just literally what is the last DateTime at which I played that song from my Spotify. It's possible to get a repeat but rare. When I hear a song I enjoy I know I could hear it again soon -- I'm not going to have to work through my entire library to hear it again -- but the odds favor hearing older stuff.
You could also remove the last N songs from the candidate list completely if you wanted to guarantee never repeating super recent tracks. Increasing the K factor would increase the favoritism of long-unplayed songs.
I think you're right. Recently I spent a bit of time writing about and playing with various shuffling algorithms, trying to see if I could find something that works better for me than the built-in shuffle.
The answer is: it's hard! An algorithm that works for a well-distributed set won't work so well for something with large clusters of similar stuff (think a mixtape vs a playlist consisted of a dozen albums from six different artists). And even when you think you've come up with a good solution, it works well six times, and then the seventh you start to find something that doesn't work quite how you like. It's a process of tweaking.
My final test case was a large playlist like you describe, since I have a few of these, too.
This is what I found worked best for me:
- (Optionally) Fisher-Yates shuffle the whole thing, then - Slice the playlist into X chunks - Shuffle the order of the chunks using Fisher-Yates - Analyze the contents of the chunks - Pick a suitable shuffling algorithm based on the contents - Shuffle the contents of each chunk
There are lots of details around things like, how recently was this artist/album/compilation played? What's the relative tempo or genre of the most recent X songs, and how "harshly" are we willing to change it up? Is this a playlist with a lot of disparate songs (by artist/album/compilation) or is it a collection of like-minded albums and artists? Is the playlist just someone's discography? etc.
It takes a lot of passes and a lot of listening to find and tweak these things to find something that works and feels good. And in the end, I don't think the people who can do this are incentivized to actually do this. Especially considering the linked Spotify article is an entire decade old by now, and the Every Noise at Once guy was let go seemingly at random by Spotify. They care about "good enough for now" more than Actual Quality.
I wish it would randomly pick the next song from the entire playlist whenever it changed songs.
Though as you say it might already be doing this now. I don't remember feeling like I'm rotating through the same 30 or so songs recently. But also I did start working around it, so I may just not be noticing.
That isn't "shuffle", that's "random".[1]
Normal people know what "shuffle" means. It's only recently (since the iPod?) that tech companies tried to blame the user when the user hit the "shuffle" button and got "random" instead.
[1] When you shuffle a deck of cards and then look at each one in turn, do you expect to see a King of Hearts three times in a row? Why on earth, then, is it acceptable to blame the user when they shuffle a list of songs and then get some songs player twice and some not at all.
i switched to apple music because of this, which does work properly (unless youre using the web client, in which case you can't click the shuffle button because it only queues up the songs from the first lazy-loaded "page", so you have to scroll all the way to the bottom, play a song from the last "page", then put it into shuffle mode)
youtube music is probably the best option for music streaming if you can stand to give them your money.
Oh it's bad with small playlists as well.
This problem exists even with a smaller playlist. My playlists have about 150 songs each. And every time it plays a certain subset of songs a lot more frequently than others.
A shuffle already implies shuffling like a deck of cards, so you wouldn’t get duplicates unless you had two of the same card, and I that’s how it was described in the manual.
I can't think of why someone would prefer a truly random song being played from a playlist rather than the "deck of cards" method.
Probably doesn't go back further than that, unless jukeboxes has a random play option.
Suppose shuffling results in ordered set [b, a, c]
Suppose user plays through the entire set. Now it's shuffled again before repating.
Suppose the new shuffle results in ordered set [c, a, b]
The user now hears c play after c
People complained that it wasn’t random. Incessantly.
So I changed it, to instead maintain a list of previously viewed items for each user, and to exclude them from the results.
And that was that. People almost immediately noticed that it had been “fixed”.
There’s mathematically perfect, and then there’s user expectations - and ne’er the twain shall meet.
For something like XKCD this is a very good idea. It mitigates two possible perception problems amongst users:
1. Regular long-term readers who see true random as less so because it seems to show them things they already remember more than novel examples.
2. People who are regular and been around a while, but not for the half the length of the site's long history, because again they'll see less of what they've already seen than they would with true random.
The issue for a site like XKCD is the fact that many won't want to be tracked so for them any such effort is wasted. You can store the data in localstorage (it is a feature that can live without needing to track the same user between different devices and UAs) to mitigate the concern, but that is usually blocked by blocking cookies due to it having similar potential for more nefarious activity tracking.
To be honest, I'd just not bother. People will still complain anyway!
Quick excerpt:
> The player said “I lost a 2:1 battle, and I get that, I know I should lose that sometimes.”
> I said, okay, so what’s the problem?
> He said “well, I lost a 20:10 battle — what’s up with that?! 20 is so much more than 10!”
He seems stuck on interpreting feedback through the lens of a linear-odds, one-shot model. The player feedback is that it shouldn't be linear, and there should be less randomness for larger numbers.
That all makes sense to me... and I suspect makes sense to him when he's not giving a talk for comedic effect.
Wow, I liked Sid Meyer a lot more before I listened to that arrogant diatribe about how stupid his players are and about how his decisions are unarguable Math-God-Given conclusions that you'd have to be A Stupid Irrational Loser to disagree with. Fuck you, Sid. You can design your game any way you want. Don't blame shitty game design on math; math didn't make you decide that combat strength should map linearly to odds of winning. That's a shit-ass combat system and not any more mathematically pure than "biggest number always wins", or using a health system like later games did. The audacity to stand up in front of people and lament how he had to get his pure, beautiful game all dirty because of the irrationality of his stupid loser players who just want a game that doesn't feel like bullshit ... come on. So much respect was just lost for that man. Never meet your heroes, nor listen to them talk about how much smarter they are than everyone else.
He's right in that players are biased when it comes to rare player success versus rare player failure. He's not right that it's irrational to have different expectations from the "simple mathematical probabilities".
The simple math works when each side is trying to hit a single target that only needs to be hit once. It does not work for medium or large fights.
No, he's not right. Humans only seem irrational when you myopically narrow your focus to one or two axes. This is something "smart" people do all the time: they're smart in one way, so everyone who acts in any way counter to what looks optimal from that narrow, simplified model is acting "irrationally". Economists will call humans irrational, but it's actually their over-simplified models that suck. Sid Meyer will call his players irrational, but it's actually his (originally) lame combat system that sucks. Rich MBAs will call lifelong employees irrational for not starting their own businesses, but they're ignoring a thousand factors that they took for granted. The people they are denigrating are incorporating more axes, more information, more context than their silly little models are.
There's a story I wish I could find about a young boy in India trying to answer his dad's math problems. His dad asks him questions like "A man wants 5 mangoes from a shopkeeper who is selling them for $4 each. How much money will he spend?" and gets increasingly exasperated that his child can't answer. But we see the child's inner thoughts, with things like "why would he spend $4 at this shopkeeper when they usually cost $2? Can't he just walk to a different shop and get them there? And what is he going to do with FIVE mangoes? He won't be able to use them all before they spoil!" etc. etc. Sid Meyer is the dad assuming his players are stupid (sorry, "irrational", meaning: stupid, losers, dumb, idiots, morons). They're not.
Now back to the thread:
It turns out that most people expect "random" to mean a random selection without duplication (at least until the source is exhausted). That is called a non-replacement randomization: once a song (or comic, or whatever), is played/displayed, that item is no longer considered as part of the pool for future selection. However, that requires saving state for the individual user to save which information has been presented to this specific user, which adds a whole lot of additional requirements for cookies, or account registration, or other things that we all generally loathe.
The fundamental problem here is that most people don't really understand randomness and probability. If they did, casinos and lotteries would be out of business (see The Gambler's Fallacy[1]). This is not a failure of education, or mental capabilities: it is a fundamental friction with the way that the human brain has evolved.
The human brain is fundamentally a pattern matching system. We look for "meaning" by identifying patterns in our world and extrapolating what actions we should take based on those patterns. As such, we assume that _all_ systems have memory because that's how humans learn and take action, so we generally assume everything else does, too. But truly random events have no memory: there are streaks that appear "non-random" to us, such as multiple tails occurring in a streak during a fair-coin flip. But streaks often occur in truly random data, we as humans just don't expect it.
The existence of the Feynman Point[2] is an example that even someone well versed in randomness and math thought that a string of six 9's appearing in the value of PI, an irrational number, was something worth noting.
[1]: https://www.investopedia.com/terms/g/gamblersfallacy.asp [2]: https://en.wikipedia.org/wiki/Six_nines_in_pi
I think you misunderstand the reason many people gamble if you are so sure of this.
(But I agree people also don’t really “get” randomness).
The people who learn that random(uncorrelated) is what it is and not what they want are part of today's lucky 10'000
Random data is highly patterned regardless. The choice of Y=everything-but-/dev/random is has no special status (ie., P(X|/dev/random) = 1).
Better than `random` is set to draw from the long tail of lower-rank-by-view comics. Then Y = the-url / user-preference / ...