How random is xkcd? (2015)
hardmath123.github.io
hardmath123.github.io
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).
We were young and not that well versed in the full range of musical expression (yet). Nevertheless, that didn't stop one of us (me? not sure) hitting it out of the park with a 3 part segue from "King of the Swingers" from The Jungle Book soundtrack to the Sex Pistols "Pretty Vacant" to one of the Bach preludes from the WTC. This sort of thing was routine on a daily basis for all of us, and we delighted in the best ones.
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
2. Your claim is not even true as written.
3. I'm tempted to assume the user has a reasonable amount of music, so it will last as long as necessary. And you can't force me not to assume that.
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.
Suppose, for example, that each side has 5 hit points, and repeatedly you roll a 2:1 die to decide who gets 1 point of damage, until one side reaches 0 hit points. The chance of an "upset", where the weaker side wins, is not 1/3; I compute it to be roughly 14%. If both sides start with 10 hit points, I compute the chance of an upset to be 6.5%. The law of large numbers means that, the more die rolls the combat involves, the less likely an upset is.
Or. Suppose that, at each step, one side has N soldiers and the other has M, and repeatedly a random soldier gets a kill; so that's an N/(M+N) chance that the first side gets a kill, and M/(M+N) that it's the other side. This would make advantages compound within the battle. Then I compute that a 2:1 initial matchup has a 5/6 chance (83%) of victory, and a 10:5 matchup has a 98.8% chance of victory.
(edit) I guess you could say I'm challenging the idea that "unit strength", such that when strength A fights strength B it's decided in one step with probability A/(A+B), makes sense as an abstract concept.
(defmemo meh (a b p)
(if (is b 0)
1
(is a 0)
0
(+ (* p (meh a dec.b p))
(* (- 1 p) (meh dec.a b p)))))
(defmemo nub (a b)
(if (is b 0)
1
(is a 0)
0
(+ (* (/ a (+ a b))
(nub a dec.b))
(* (/ b (+ a b))
(nub dec.a b)))))More than "players don't understand math", this might be a UI or tutorialization issue. I.e. presumably it was unintuitive because people imagined more complicated ways it might be working behind the scenes, causing large absolute stat-disparities to feel like they should work differently despite being in similar ratios. It's a case where showing an explicit odds-of-success display might have helped, though XCom famously showed how that can backfire...
(Revolutions was a deliberate simplification of the Civ formula, so they could try to appeal to console / mobile gamers rather than the traditional hardcore PC audience.)
I think this is exactly it. And then Sid Meyer calls his players stupid and irrational for assuming the game had more depth than it actually had. For assuming a celebrated game designer would put even a modicum of thought into making a combat system that was balanced, made sense, and felt good.
It's like selling a gallium spoon and then calling people stupid when it melted in their soups. Sure, if you know a lot about gallium, you wouldn't be so stupid and irrational as to put it in your hot soup. But it's a metal spoon that you bought from a reputable vendor. Spoons go in soup. They were being completely rational; it's just that they were tricked into assuming a product was less crappy than it actually was.
I think this is overstating what Sid Meier says in the talk. His original goal was to make his simple combat stat system clear to users by describing its odds as odds conventionally are described.
> For assuming a celebrated game designer would put even a modicum of thought into making a combat system that was balanced, made sense, and felt good.
That's exactly what he did, through player testing! Through practice and player feedback seems to me like a perfectly reasonable way to uncover an intuitive notion of unit strength. It's not like he said 'they're odds, stupid! learn how to understand odds.'. He recognized that player intuition and fun was the real goal, and his team gradually made the combat system more sophisticated.
Except that odds values don't add on to each other. It sounds like the numbers only worked like odds in a single way, and not in other ways. The system was inherently contradictory, and confusion is not irrational in that situation.
And it's easy to clarify something as odds by making it two opposing percentages out of 100.
1:3 means the second outcome (that on the right-hand side of the ':' symbol) is 3 times as likely as the former outcome, which is true when the likelihood of the first outcome is 25% and the likelihood of the second outcome is 75%.
1/3 describes the chances only of one of the outcomes, and fixes it at 33⅓%. If there's only one other outcome, its likelihood is 66⅔%.
Is the 'addition' you're talking about just one of the readings of the first syntax, or did I miss something else in the video that made the initial presentation of those odds figures surprising?
Sorry if my terminology is off; it's been a long time since I did any stats
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.
Paper itself: https://www.nowpublishers.com/article/OpenAccessDownload/RBE...
Abstract: "Behavioral economics began with the intention of eliminating the psychological blind spot in rational choice theory and ended up portraying psychology as the study of irrationality. In its portrayal, people have systematic cognitive biases that are not only as persistent as visual illusions but also costly in real life—meaning that governmental paternalism is called upon to steer people with the help of “nudges.” These biases have since attained the status of truisms. In contrast, I show that such a view of human nature is tainted by a “bias bias,” the tendency to spot biases even when there are none. This may occur by failing to notice when small sample statistics differ from large sample statistics, mistaking people’s random error for systematic error, or confusing intelligent inferences with logical errors. Unknown to most economists, much of psychological research reveals a different portrayal, where people appear to have largely fine-tuned intuitions about chance, frequency, and framing. A systematic review of the literature shows little evidence that the alleged biases are potentially costly in terms of less health, wealth, or happiness. Getting rid of the bias bias is a precondition for psychology to play a positive role in economics."
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 / ...
* I encourage you to play with the STS code.
* It also segfaults all over the place, which is actually very disturbing considering that it’s technically part of the US government’s computer security project.
Well, package that computes stats on number series to test variopus notions of randomness - it's not as if pwning the STS will let you play a game of nuclear war.
All the same, there's an exercise for any budding numerical programmers, read up on the suite, build it, run it, static analyse it, valgrind it, and iron a few wrinkles out.
https://csrc.nist.gov/projects/random-bit-generation/documen...
Got to be worth a humble brag in an application or two | make contacts in NIST.
https://scholar.google.com/scholar?cluster=189992958054266148
The paper also reports in section 7 the state-of-the-art in statistical tests --- DIEHARD and NIST STS seem obsoleted by TESTU01.In the paper, the authors examined evidence of nonrandom behavior and created several probability models for these events under the assumption of a random shuffle. Their conclusion was:
> Much of the evidence of nonrandom behavior reported by Steven Levy and others does not hold up when the probability models of the events are determined. Our results show the probability models for a random shuffle in many cases do not match the intuition of users. In addition, our statistical tests show the long-term occurrences of these events are within expectations under the assumption of a random shuffle.
I'm not sure if this was something Apple implemented after 2009.
So Apple had to take their generally true random algorithm and make it intentionally less random so it worked like people implicitly expected it to. Makes me wonder how many things we really are "holding wrong" because dev expectations didn't line up with how people actually use something.
(It was a bad way of stating it, that's on me)
nvm
Also, there are plenty of non-uniform random distributions.
- Out of 1500 comics (at the time of the article), 45 random selections gives you a 48.656% chance of a duplicate, and 46 gives you a 50.196% chance.
- Out of 2873 comics (as of right now), 63 random selections gives you a 49.579% chance of a duplicate, and 64 gives you a 50.685% chance.
2929 comics is the most from which randomly selecting 64 will have a greater than 50% chance of having duplicates (50.00854657587404%).
https://en.wikipedia.org/wiki/Coupon_collector%27s_problem?w...
Video games are known to cheat a lot, usually in the player's favor. The Tetris randomizer for instance is well documented. Early games drew pieces truly randomly, but now, the standard is to draw randomly from a bag of all 7 pieces until it is empty, then repeat, limiting flood and draught. Along the way, other algorithms have been used with the same purpose.
But sometimes, even the numbers are fake, for example, a 95% success rate may be closer to 99% in reality because it matches more closely what players feel 95% should be like.
Turns out, the company wanting the game got scarred of some patent that invoked the word random, so we had to reprogram the thing essentially do the same as that player. We had multiple sequences of randomized questions, and the game pick one of the sequences to play back in order when started.
In [1] it says that numbers have a 0.5034 probability of being odd due to rounding errors in the algorithm that picks a number in a range, which is unacceptable for a simulation, but may actually be better than a real coin toss [2]. The raw RNG is also flawed but not that badly [3]
[1] https://fuglede.dk/en/blog/bias-in-net-rng/
[2] https://arxiv.org/abs/2310.04153
[3] https://gist.github.com/fuglede/772402ecc3997ada82a03ce65361...
I'm assuming I either hit an PRNG bug (after all, I encountered a compiler bug in university already), or more likely, that I simply imagined the issue or bad bad luck with the data. Never did a statistical analysis after all.
1. Randomness is inherently counterintuitive and humans in general really struggle to comprehend its ramifications. Read “Fooled by Randomness” or a million other things about this.
2. When a lot of people see something which offers a random sample they expect a random shuffle. In particular if you’re making any kind of playlist thing and you have a feature which does random samples not random shuffles people will hate your feature and you’ll feel superior because you’ll think they are wrong but actually you are the one who is wrong. You need to build a shuffle of some kind. Changing your sampling strategy to be “less random” thinking that it will coincide with peoples’ intuitions is making it even more wrong than before.
First, I greedily requested 10,000 random numbers from xkcd with a script. These numbers are here so nobody need re-commit my deed: https://gist.github.com/tonyb486/0da38e7575071f241551d14101a...
Then, I filtered out all numbers 2048 and above so that I just had 11 bits of entropy from each number from [0,2048). I converted that to a stream of binary in ASCII, 11 bits per random number.
I fed that list of 78100 bits into STS, as 100 streams of 780 bits. It segfaulted, but it had already written out some results:
------------------------------------------------------------------------------
RESULTS FOR THE UNIFORMITY OF P-VALUES AND THE PROPORTION OF PASSING SEQUENCES
------------------------------------------------------------------------------
generator is <xkcd.ascii>
------------------------------------------------------------------------------
C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 P-VALUE PROPORTION STATISTICAL TEST
------------------------------------------------------------------------------
13 15 7 9 7 6 9 11 17 6 0.137282 97/100 Frequency
13 5 10 12 11 7 4 10 12 16 0.191687 98/100 BlockFrequency
13 11 14 9 2 9 10 7 13 12 0.249284 97/100 CumulativeSums
11 10 12 11 1 10 9 15 8 13 0.181557 98/100 CumulativeSums
6 6 8 18 9 8 11 14 7 13 0.122325 99/100 Runs
16 7 6 12 13 9 7 14 9 7 0.275709 97/100 LongestRun
10 13 12 0 23 0 18 0 24 0 0.000000 * 99/100 FFT
Delightful.almost??
But for the first few bits maybe "almost".
My mental model is that an unbiased random stream of 1's and 0's should converge on 50% 1's and 50% 0's over time, not 49% 1's and 51% 0's.
Looks like it's a language ambiguity thing I'm not quite getting.
So if ypu ever see a random pick equate to 50/50, the end of the universe is upon us.
2873 unique numbers printed, so I got all of them for xkcd as of Dec 28, 2023.
The lowest occurrence of a number 44 unique entries for 332 and 1829.
The largest occurrence of a number was 99 unique entries for 2007 and 2230.
Average occurrence was 69 entries, 134 unique numbers occurred 69 times.
What does this mean to me ? Nothing, but maybe to a mathematician it will mean something :)