CoRecursive #124

Random to Whom?

Dice, Tetris, and a lunch bet over what random means

Random to Whom?

I found a comment on the Call of Duty Mobile subreddit. Kevffinn: COMPUTERS CANNOT GENERATE RANDOM NUMBERS AND ANY SUGGESTION OTHERWISE IS FRAUDULENT.

I’m not sure about the fraud part, but what does and does not constitute a random number is a surprisingly deep question. So I built a randomness detector, and I bet Don that we would not be able to produce a truly random number. Loser buys lunch.

Transcript

An All-Caps Reddit Claim About Random Numbers

Adam: Hello, welcome to CoRecursive. I am Adam Gordon Bell, and I dragged Don over again. How you doing, Don?

Don: Oh, pretty good. Yeah. It’s a hot one out there, but we made it.

Adam: Okay, so today I wanna talk about a random subject, like literally random as in randomness. I feel like it’s super interesting to me, and I’m not clear if it’s interesting to anybody else. So yeah. I found this comment on Call of Duty Mobile Reddit. Did you play Call of Duty?

Don: I’ve played, like, several Call of Duties, but I’ve not played the mobile.

Adam: Okay, so user Kevffinn? Kevffinn says:

Don:

Computers cannot generate random numbers and any suggestion otherwise is fraudulent.

Reddit comment by Kevffinn, in all caps: computers cannot generate random numbers and any suggestion otherwise is fraudulent
The comment, in its original caps, closing a reply about loot-crate progress. r/CallOfDutyMobile, March 2025.

Adam: It’s all in caps, man. You read it very calm, but this is like, “Computers cannot generate random numbers.” Yeah.

Don: The guy is screaming about it. He’s, he’s, he’s peeved.

Adam: And so that’s what I wanna talk about today. Can computers generate random numbers? ‘cause there’s lots of comments like that. I found this one on another Reddit, which says… Oh, I like this one. So this is Casino Blackjack online. This person says, “Hello, I’m trying to study blackjack, wondering if I could make some money playing in an online casino.” And then user thepancakewar responds.

Don: Well, I’m still laughing at the guy saying, “I want– I’m going to study blackjack to make some money.”

Adam: Yeah, not.

Don: Not the best life plan, but the response by thepancakewar is, “Never completely rigged beyond rigged. No such thing as random in a computer. They can be adjusted like slot machines.” And then the comment to that was removed.

Reddit thread on r/blackjack: a poster asking about live casino blackjack, and thepancakewar replying that there is no such thing as random in a computer
The other thread. r/blackjack, December 2023.

Adam: Yeah, I wonder what he said. It’s gone. And there’s like a million comments like this, and people debating it online, right? Whether games are rigged is one thing, and then whether something can be random is another. ‘Cause I fully believe that, yeah, probably onlineblackjackcasino.com is rigged.

Don: I mean, they’re in the business of rigging.

Pick a Side: Can We Make a Random Number?

Adam: Cause I want to make a bet, so here’s the bet. That we can make a random number. So what side of the bet do you wanna take? I’ll bet against you.

Don: But that we can make a random number.

Adam: Either we can or we can’t. That guy says that we can’t use a computer to make a random number. So can we, is the question. Okay, let’s pick a wager. Well, pick a side. It’s more fun if I can get you to bet.

Don: Oh, sure. Yeah, I think we can make a random number.

Adam: Let’s do it. Okay, so then I’ll take the other side. I’m on Team Kevffinn. “Computers cannot generate random numbers, and any suggestion otherwise is fraudulent,” is what he says. I’ll take just the we can’t generate a random number. I’ll leave fraud out of it. Okay. So the problem, first problem is, you can’t generate just a singular random number, if I just say… Actually, there’s a great xkcd. Have you ever seen it? It looks like this, where it’s generate random number:

Don:

Return four chosen by fair dice roll guaranteed to be random.

xkcd 221: int getRandomNumber() { return 4; // chosen by fair dice roll. guaranteed to be random. }
The four really was a fair roll. The trouble is that he published it. xkcd 221, "Random Number", Randall Munroe, CC BY-NC 2.5.

Adam: Because like, yeah, if you just return four and four was chosen randomly, is that a random number? Not really what people mean by a random number, right? So I think that to successfully generate random numbers, we need to be able to like…

Don: There has to be an equal chance for every answer.

Adam: Yeah, but there needs to be like a continuous number of them. If we’re just generating one, how do we know if it’s random or not? And so I built a program to judge whether something’s random.

The Bench, the randomness detector: a dataset dropdown top right, five instruments down the left (Look, Count, Zip, Predict, Crack), and the tape of Don's F/J presses in the main panel
The program that decides the bet. One dataset on the bench, five instruments down the left, from the weakest observer to the strongest adversary, and a verdict that can only ever be NOT RANDOM or undefeated so far.

Don: How does it judge?

Adam: Well, that’s what we’re gonna find out. We’ll be able to produce, you know, many random numbers, and we’ll be able to tell if they’re random or not random. So you’ve picked a side. Then we need something to wager.

Don: Well, I mean, usually you’d put that up front and then you’d make a wager.

Adam: No, it’s better this way. I get you to commit to the bet. We bet our mortgages. Yeah.

Don: I’ll buy you a cup of coffee.

Adam: Okay, so we’re playing for a cup of coffee. Tim Hortons, I assume.

Don: Well, technically you owe me a lunch, so you could use that.

Adam: Oh, okay. Okay, we’ll do it for a lunch. All right. The bet is on. Okay, here’s my first test. So I think the first way that we could try generating a random number is just ourselves, we can try to just come up with a series of random numbers and see if they’re random. Like, make them up off the top of our head.

Don Versus the Oracle: F or J

Adam: Okay, so this is a game created by somebody, a professor, I think, Scott Aaronson. And so what you’re looking at, is it just says the recorder, you versus the oracle, so the oracle is just a little Python program that this professor wrote, and the idea is I’m gonna give you the keyboard, and you’re gonna press one of two keys, one with each, keyboard press, either F or J.

Adam: And the idea is to do it randomly. You’re basically generating a random binary sequence, right? And so if something is random, somebody shouldn’t be able to guess it, so they should be able to guess it, I guess, like half of the time, because it’s zero and one, right? So chance would be fifty percent.

Adam: So just press F and J, and you’ll have to do it a bunch, and it’ll try to guess after it sees… Oh, look at it go. What do you see it saying?

The recorder: a big percentage of presses predicted, the count of presses, and a row of hit and miss marks
The recorder Don was looking at. Press F or J; the oracle calls each one before you press it, and the number is how often it was right.

Don: Oh, it says you– of 97% of my presses predicted.

Adam: So when you go to press a key, right before you press a key, it predicts what you’ll press, and then you press it. So you’re already up to 250. How’s it doing at guessing?

Don: 87%.

Adam: So try harder. Try to be more random. Oh, you did get a good streak of randomness. At least it couldn’t predict it.

Don: Down to 80%?

Adam: Oh, you’re getting more random.

Don: 79%.

Adam: I wonder if this can train you to be random.

Don: Yeah. So you can see, like, if I press J a bunch, it misses a couple times, but if I keep pressing J, it’s like, “Oh, he’s pressing J all the time, so I’m gonna predict J all the time.”

Adam: So, I mean, I think this gives us our first sort of property for randomness, which is something’s random if it can’t be guessed.

Don: 74%.

Adam: Still not random though, right? Like random you’d have to get 50, but you are bringing it down. Maybe if we give you enough time, you’ll be able to get more random.

Don: Yeah, ‘cause you have to keep switching up your pattern. Got it down to 73%.

Adam: So now we’re looking at all your binary. Here’s all your answers. So at first there’s a lot of alternating, so it kind of figured that out. And then there’s a string of zeros. So we can look at this.

Adam: So the way that program works is actually really simple. I think it has whatever the various five long sequences are of ones and zeros. Like say there’s 25 possible sequences, and then it just scores whichever you’re in, and then it just guesses like, “Oh, this is the little pattern that he’s…”

Don: Yeah, that’s what I got onto and that’s what I thought I was doing.

Adam: Yeah. And so we can examine whether it’s, you know, random in a number of ways. So one would be a histogram. So a histogram would just be, you know, if you’re rolling dice from one to six and you roll it enough times, you should get a pretty even spread between all the ones and sixes, the histogram, all the numbers should be pretty even. Yeah.

Don: Depending on how many rolls you make.

Adam: Yeah, like at first, one will be higher than the other, but over time they should even out. But so for the histogram you did well. So looking at the difference between zero and ones, they’re pretty even, which is what you would expect, right? Like if you always just hit the F key for one, that wouldn’t be random at all.

Adam: Yeah, this is your numbers. We could also look at your numbers like visually. And I mean, you could see a pattern when we look at it as a cube, like you can see when you were just straight alternating…

Don: And then I learned what it was looking for.

Adam: Yeah, you definitely are becoming more random over time. All right, so that’s pretty good. I mean, strictly this is a fail because you didn’t get to 50.

The Predict instrument on Don's 530 F/J presses: 73%, with a learning curve that falls but never reaches the 50% chance line
Don's actual run, replayed: the oracle's hit rate across his 530 key presses. It falls, but never gets near the coin-flip line. Game after the Aaronson Oracle.

Don: Well, I didn’t have enough time.

Adam: All right, you’re not gonna concede that one. All right. Let’s keep going then.

Don: Well, you said it yourself, I became, I was becoming more random, so if that’s a trend line…

Adam: Yeah, you’ll get towards perfectly random.

Don: I’ll get towards perfectly random.

Tetris Knows When You Need the I-Piece

Adam: Right, so now we’re looking at Tetris. So people have a weird perception of randomness, right? You’re doing, you did pretty well in that game, but often people have certain biases and they kind of expect randomness to reflect that. So Tetris obviously was huge, in its time. Did you play a lot of Tetris?

NES Tetris (Nintendo, 1989). The statistics panel on the left is counting the same thing our histogram counts.

Don: I didn’t play a lot of it. I played some of it.

Adam: So back in 1989, you know, Nintendo released Tetris, and it was using a pseudo-random number generator to pick the various, pieces. And the game obviously became huge, so it just kind of rolled a dice. How many pieces are there? Seven? It was like a seven-sided dice, if that existed. You know, just picking a random piece. Which makes sense, if their pseudo-random number generator was accurate enough, that seems like a good way to pick it.

Adam: But the problem with random numbers is there’s streaks in it. There’s nothing saying you can’t occasionally roll the dice and get…

Don: A couple times in a row, yeah.

Adam: And get six the same time over and over again. But people have a hard time accepting that. Right? So the guy named Henk Rogers, Henk Rogers is the person who brought, he didn’t create the game, but he brought it, you know, out of the Soviet Union. And, in the height of the game’s popularity, he was always getting harassed by people.

Adam: So he was at a rental car agency, getting his car, and the person there told him that the game is watching her, and it knows when she needs that long I-piece, and it won’t give it to her, and so the game is cheating, right? And she was quite upset, like this game- I can move on. Yeah, yeah.

Adam: Have you ever felt that way? It’s like, oh my God, it’s gonna… It’s trying to cheat against me. And in fact, I had this previous episode on this game called HATETRIS, which is, it’s the simplest thing in the world. It’s a version of Tetris except the computer always picks the piece that you least need. So it looks at, what shapes you need and it picks the one that’s the least gonna work.

Don: It’s a rage quitting.

Adam: Yeah.

Don: I’ve got one for anyone who played XCOM 2. It, calculates percentage of, that you’ll hit a target. And anyone who’s played XCOM 2 knows that you’ll have a 98% chance to hit a target, and then it’ll miss, and it’ll throw off your whole game, and you’ll be very upset.

Adam: And is that random or is that them cheating?

Don: It was the game cheating for sure, 100%.

Adam: And so people get mad, right? They expect a certain thing from random. I don’t know about XCOM 2, maybe they were cheating. It’s hard to tell. But I guess in the case of Tetris, it was literally a random roll, but it frustrated people so much. And then this guy who brought the game from the Soviet Union, he was talking to the people at Nintendo about this, and they just suggested like, “Well, we should just change what the bias is on the randomness.” People don’t like random. Random’s too random. Let’s change it, right?

Can a Bag of Seven Pieces Fix Tetris?

Don: To make sure that the game is fun, ‘cause that’s the purpose of the game, right? So if people are upset playing it, then…

Adam: And it’s like we have this idea of fairness, which isn’t really a property of random numbers, but we feel like it’s unfair if we really need that long I and we don’t get it.

Adam: So then in 2001, they fixed it. They introduced Tetris Worlds, and they shipped with this bag idea, right? So it was a plain text file, I guess, that came and had the rules for how the randomness worked. But the most important one is it says like, “Next piece queue size is eight, and remove from bag after use.” So basically it was like they put all of the seven pieces in a bag, and each time they pull one out and drop it to you…

Tetris Worlds (THQ, 2001), the first game to ship the seven-piece bag. The queue on the right is the bag being dealt out. Rule per Tetris Wiki.

Don: It gets removed from…

Adam: It gets removed. So that way you can’t get three Is in a row because once that I’s been pulled out…

Don: So yeah, you won’t get any duplicates. Unless it was at the end of the bag. As you cross over the boundary, you might get a double.

Adam: Yeah, and people like this a lot more. So if we look at the original Tetris now, we’re just looking at the random pieces that come out of a Tetris game, and they do look pretty random. And if you look at a histogram of them, it’s the same thing, right? It’s like you do have the same probability even though it never seems like you get that long I-piece, right? I always felt like, “Oh, I saved the spot on the end,” and it never comes.

A strip of Tetris pieces from the 1989 NES randomizer, colored cells with letters, including a long run with no I piece
The 1989 NES randomizer: every piece equally likely, and still a 27-piece stretch with no I. The odds are fair. The drought is what fair odds look like. Randomizer per Tetris Wiki.

Don: ‘Cause you have forgotten all the times you got one and didn’t need it.

Adam: ‘Cause you just remember, like, it’s more salient to you when you don’t get the thing you need, right?

Don: That gets deleted from your memory, so you… And then I…

Adam: Frustrating. It’s like finally, okay, I gave up on filling that line, and it comes.

Don: And then it’s like, “Oh, it’s doing that on purpose. It…”

Adam: Yeah.

Don: “Me.”

Adam: And so the seven bag approach they did, it actually looks the same for me looking at all these numbers, but technically, it gives you a much flatter. So if we look at the histogram now, it’s completely flat. So you will always get– You won’t have a big run without getting a certain piece. So it’s technically less random.

Adam: But I think this, relates to that, Kevffinn, whose side I’m on, right? His all-caps frustration is about this idea of, like, numbers not coming out the way he likes. Maybe. I mean, maybe he’s right and there’s no random numbers, or maybe he’s just frustrated because in Call of Duty Mobile, he had the same thing as your XCOM problem and it’s “Ah, 98%. Are you kidding me?”

Don: What part of Call of Duty Mobile is reliant on random number generators?

Adam: He’s talking about loot boxes?

Don: I’m pretty sure he’s talking about loot boxes and, like, they say that there’s, an X number of X percent chance that you’ll get this item in this loot box. And he’s like, “You know, they’ve rigged it.”

Adam: You’ll never get that. But he makes a bigger statement. He’s just like, “Computers cannot generate random numbers.” He’s not saying “Oh, I got stiffed on this loot box.” Somebody put-

Don: Puts all caps. They’re mad about something.

Adam: Yeah, that’s true. You have not been on enough gaming forums.

Don: Yeah, no, this guy’s mad, right? And he’s mad because he probably spent like $100 trying to get some cool weapon skin and he didn’t get it.

Adam: Okay, so here’s where we are so far. If we’re gonna generate random numbers, having Don randomly press keystrokes is probably not the way.

Don: It’s inefficient.

John Carmack’s Random Numbers in Wolfenstein

Adam: Yeah. Okay. Next, one of my favorites.

Don: Wolfenstein.

Adam: Wolfenstein. Did you play Wolfenstein?

Don: I did, yeah.

Adam: I played Wolfenstein so much.

Don: It was good.

Adam: Okay, so an idea would be Wolfenstein has randomness in it. There’s the chance that you’re, like, hit by one of those soldiers, for instance, right? It’s not guaranteed. There’s a randomness generator in that. So…

Don: Right, to simulate the soldier’s aim. Yeah. But I don’t think it would be truly random. It was probably based on, the type of enemy you’re going up against. Some might be better at hitting you than others.

Adam: Yeah. So it would be some probability, okay, this guy hits you so often with some percentage, with some strength, but then choosing if that, you know, cashed out to actually hitting you, you need to like roll a dice or something, right? And so if we just take however Wolfenstein did that roll a dice part, maybe we can generate random numbers.

Adam: So in the Wolfenstein source code, they had a random number generator of sorts, and it looks like this. So in the assembly of Wolfenstein, and there’s a comment, and it says like, “Assembly portion of the user manager. This is John Carmack’s table of pseudo-random numbers, and we put it here because we couldn’t figure out where it should go.” Nice.

GitHub view of ID_US_A.ASM from the Wolfenstein 3D source: the header comment calling it John Carmack's table-driven pseudo-random number generator, and the start of the 256-byte rndtable
256 bytes typed in by hand, filed "in the User Mgr because we couldn't figure out where it should go." Wolfenstein 3D source, ID_US_A.ASM.

Don: Yeah, solid, comment.

Adam: Yeah. Where should this go? I don’t know. Put it in the assembly at the top. Yeah. But so his random number generator…

Don: Was typed in by hand.

Adam: Is typed in by hand, right? It’s two hundred and fifty-six numbers, and the numbers all have a range, you know, from zero to two hundred and fifty-six. Yeah. So it’s like hexadecimal numbers. So you could take the series, right? And if you need to do a random number generator, you know, you just start at a specific spot, and then each number, each time you need a random number, you move along.

Adam: So I mean, I feel like it fails right away because it’s just like a list of numbers. But those numbers could’ve been generated randomly, right? Could’ve rolled dice to come up with it.

Adam: But then in the actual assembly, the way it works is when you play Wolfenstein, it has this. So it says… I don’t- I can’t read assembly. But basically it says if randomize is true, then we get the system time to pick an offset into that and then as you play, that’s the beginning of the game, they just move through that list.

Adam: So, I mean, it works, right? I never noticed repeated behavior in Wolfenstein. Like, you know, they always miss the first shot and then hit the second on this level. Like, I don’t know. Maybe it existed, but I didn’t notice.

Adam: We can test it actually, ‘cause I pulled the numbers. So here’s Carmack’s 256 numbers. That’s hexadecimal if we put them in decimal. So here’s the histogram of them. So we’re looking at basically how often you would get one of these numbers in the game.

Adam: So it’s not completely random. This value, whatever this is, must be like 190-ish or something. Happens a lot. So there’s repeats, but because there’s 256 values of 256, you will never get whatever this number is. Like, it’s just impossible, right? So it’s not actually random, but it feels like it. As you play the game. You know, if you look at it as a cube, it does look random. It’s like pseudo-random, right? Okay. Next thing that id Software does is release this.

Don: Doom.

Adam: Doom.

Don: Yeah. Everybody knows Doom. It runs on everything. It can run on your fridge.

Doom (id Software, 1993). Every hit, miss and monster twitch in this clip came out of the same 256-byte table, read from the top.

Adam: Running your toaster?

Why Doom Threw Away Carmack’s Randomness

Adam: Okay. So they have the exact same table in Doom, like the exact same numbers. Just, you know, why not? If it worked as, we copy that over to the next file, right? They changed one thing, which was they got rid of the random time. So rather than starting…

Don: Getting system time.

Adam: Yeah, instead of getting system time and picking that as the offset in your random numbers, they just start at the beginning. And so your first random roll is here, the second one there, second one there. Basically, they threw away part of the randomness of their pseudorandomness. Any ideas why? Laziness.

Don: No, I’m not sure. Maybe they’ve thought that it would improve the spread.

Adam: It was because of replays. So they wanted to be able to have replays of you playing the game.

Don: But was there a replay mechanic?

Adam: Yeah. See, this is the problem if I do a gaming thing, Don will find problems. In Doom’s title screen mode, if you left it sitting at the title screen, it would start playing through prerecorded demos.

Don: Oh, so the thing that it plays as part of that was configurable. You could drop in another demo and have it play something else?

Adam: Yeah, and it says if you did Doom-record and you gave a file name, it would record you playing, and then you could play it back. And the way it did that was it just recorded your keystrokes. But the only way that would work is the game had to be totally deterministic. Otherwise, yeah, if you accidentally got shot in the replay, ‘cause it’s got a different point in the random number generator.

Don: They can replay exactly what happened to you.

Adam: So the replay was actually playing through the game.

Don: Yeah, it’s just strange that that was the impetus behind changing from the system time since it doesn’t… That’s not like a flagship feature that everybody was using…

Adam: That’s true.

Don: Case is pretty limited, right? It’s like, oh, you can change the demo reel that it’s playing on the title screen. Like…

Adam: Well, they had, they wanted to ship a demo reel with it, and somebody’s like, “Let’s just comment out this feature.” So they made it less random basically.

Don: Yeah, I guess.

Adam: So if you look at the random numbers generated, what we’re looking at is all the random numbers used in a Wolfenstein game put on like a grid, and you can see the pattern when you do it. Like it doesn’t look like noise. There’s kind of rows of stuff, and that’s because you’ll start at a random point in the sequence, but then you’ll loop through it.

Adam: But if we look at the Doom one, it’s the same sequence, but it should always start at the same point. If you look at all the random numbers used in, a Doom game and you set the offset so that it makes a square at 256 where the thing loops, you can see that you’re back at the beginning of the random number generator.

Doom's random stream folded at width 256: the noise lines up into vertical stripes
Every random number a Doom session draws, wrapped at 256 columns. The same table, read from the same start, over and over. Table from m_random.c.

Adam: Now, I don’t think anybody could feel this, right? Like, you know, because these random numbers are being used for all different things throughout the game, right?

Don: Yeah, it wasn’t noticeable by the player.

Gzip, Statistics, and the Digits of Pi

Adam: Oh, there’s another way to tell randomness that has to do with my last episode, right? What is this counting? Which is basically zipping, right? So if I take truly random numbers, then you can’t compress them. So if I just run the random numbers through like gzip there’s no pattern. So they can’t do anything with it. So if I look at the Doom ones, it compresses like 1,800 to one because it’s just a repeating pattern. Yeah. It couldn’t be easier.

The Zip instrument on Doom's random stream: 1,899.6 to 1, a megabyte of random fits in 552 bytes
Zip as a randomness test. A megabyte of Doom's "random" numbers squeezes to 552 bytes, because it is one 256-byte table repeated.

Adam: Whereas if you look at Tetris. So if you try to zip the original random Tetris, it doesn’t actually shrink. It gets 3.4 bits per piece. But if we go to the bagged one… So in theory, the bags make it a little less random, so it should compress more. Okay, so now it’s able to compress it to 1.75 bits per piece. So basically, there’s less information when you’re less random.

Adam: And you could also count things. So the classic way to determine if something is random that they used to use is just statistical, analysis. If you took a whole bunch of dice rolls, and you put them into a statistics program, and it’ll say like, “Six comes up way more often than one-sixth of the times,” right?

Adam: So I built this little program, Claude built this little program that’s a rip-off of this tool called ENT, which is a measure of entropy. And so it tries to tell you if your data, has a statistical anomaly. And we can see here that it says, “This data is impossibly even.”

Don: Dice are never this fair.

Adam: So it’s saying for the Tetris 7-bag, it’s saying this is too even.

Don: So you’ll never, because in a truly random system, you will get doubles more often.

Adam: Where if we go to the original NES random, then it says all seven pieces are equally common. Fair, says this test. Okay. So I don’t know. We’ve validated my tool for determining if something’s random or not, I guess. Yeah, how you feeling about the wager? So far we haven’t found anything to be random.

Scoreboard after the first gauntlet: Don, two Tetris randomizers, and Carmack's table against five instruments
The scoreboard so far: Don, two Tetris randomizers and Carmack's table. A row is only undefeated once all five instruments have run, and nothing has got there yet.

Don: Oh, you haven’t found anything that has a pattern that can’t be predicted?

Adam: Yeah. Isn’t that the same thing?

Don: I mean, you could use pi.

Adam: That is a good thing to try. So why would that work?

Don: It has a non-repeating pattern.

Adam: Pi has a non-repeating pattern. That’s true. So I actually have pi as an example. I put in all these data sets. Okay, so if we look at the digits of pi… Why can’t we see it? Oh, it’s not working?

Don: Your program broke because it’s truly random. You owe me a lunch.

Adam: Exactly. Okay, so now we’re looking at the digits of pi. If we look at as a histogram, I mean, that could be random, right? It’s definitely covered all of them.

Don: And valleys, yeah.

Adam: Yeah.

Don: Static.

Adam: Yeah, when we look at it visualized, it definitely looks like static. I don’t see any patterns. So the statistical analysis says this is seemingly satisfactory. As far as this can tell, pi is random. We can try to zip the digits of pi. So if the digits of pi are truly random, it shouldn’t zip because there’s no pattern, right? So we…

Don: Nothing to squeeze.

Adam: Yeah, so the zip file end up slightly larger just because of the, zip header. Okay, so we’ve made progress. I mean, you have. I think I might end up owing you lunch. Digits of pi is our best category so far for generating a random number, right?

Don: Or the imagine digitizing the cosmic microwave background.

Adam: Yeah. Okay, let’s keep going.

Stan Ulam, a Sawed-Open Skull, and Solitaire

Adam: Okay, so this idea about just using some numbers you generate yourself as a source of randomness. Like they didn’t come from John Carmack. It’s like a much older idea. Generate some random numbers somehow. This is Stan Ulam, Stanislaw Ulam. Stan worked, I believe, on the Manhattan Project. So one morning in 1946, he woke up and he was unable to speak. Doctors, thought he had a brain tumor.

Stanislaw Ulam's Los Alamos wartime security badge photo
Stanislaw Ulam, Los Alamos badge photo. Los Alamos National Laboratory.

Don: Oh.

Adam: So they sawed open his skull. Doesn’t sound like how I would wanna be treated if I stopped speaking. But they sprayed his brain with a newly discovered thing, called antibiotics. So a few weeks, in the hospital, he had to recover, and during that time, he was a mathematician. He wasn’t allowed to do any math. “Take it easy on your brain. We just, you know, cut off your skull a while ago.

Don: Don’t do any math.

Adam: Don’t do any math.” Right? So he sits in the hospital, and, he decides to play solitaire. So he’s playing solitaire over and over again, he gets bored, and he comes up with this idea it’s not a question of whether I can win at solitaire. It’s like, how often can anyone win, right? He wants to know…

Don: No, he shouldn’t be doing that.

Adam: But he goes to the math, right? He’s like, “What’s the probability of, like, actually winning, a solitaire game?” That’s hard to figure out just by calculations ‘cause there’s lots of moves involved, so this is a quote for you to read:

Don: I wondered whether a more practical method than abstract thinking might not be to lay it out, say, 100 times and simply observe and count the number of successful plays.

Adam: So he recovers and he goes to Los Alamos, to work on their big bomb. He takes this idea of like, instead of trying to figure out all the math…

Von Neumann’s Middle Square and a State of Sin

Adam: Can we just simulate things? So he takes this idea to John von Neumann, and John von Neumann was known– these were all the smartest, brightest people that they could scrape up in physics, and John von Neumann was known for being, like, scarily smarter than everybody else, right?

Adam: But so he’s working on this problem of how they figure out the atom bomb is gonna go off. So they need to do a simulation of, you know, they bombard these neutrons. They bombard the atoms. And then the neutrons come out randomly and they hit other particles. I don’t know how atom bombs work that well, and they cause other ones to emit neutrons in it and it takes off…

Don: At criticality.

Adam: So there’s a randomness to it and he needs to figure out how to do all the calculations for this when there’s this component he can’t understand. So he comes up with this idea, I need some way to simulate randomness, I need my calculations to be able to do the John Carmack trick, to be able to be like, “Okay, now I don’t know which way the neutron’s gonna go. Let me look it up in this table.”

Adam: So he comes up with this real formula that he calls, middle digits, which is that you square a number and then you take some of the digits from the middle and you just assume that those are random ‘cause they’re in the middle.

Don: Middle out.

Adam: Middle out, right? So you pull out the middle digits, that’s your random number, and then those middle digits that you pull out, you use them as the seed for the next thing.

Adam: And so here’s his data, which he called middle square. So he starts with six two three nine. He squares it, he takes the middle digits, and then he gets nine two five one. He takes that, you know, squares it, gets five eight one zero, and so on.

The tape of von Neumann's middle-square generator seeded with 6239: white numbers until draw 111, then an orange repeating cycle 4100, 8100, 6100, 2100
Middle-square from seed 6239. White is the living sequence. At draw 111 it hits 4100 and everything after is the same four numbers forever. Every one of the 10,000 possible seeds dies by then.

Adam: So he gets a good source of randomness up until it starts repeating. You get forty-one hundred, which gives you eighty-one hundred, which gives you sixty-one hundred, which gives you twenty-one hundred, and it starts looping, right? So he can get randomness to his thinking until a certain point. And so this was the first attempt at randomness. If you look at it visually…

Don: Yeah, it falls into a pattern. After…

Adam: It looks like random snow until it just becomes a repeating pattern. If we run a statistical test or try to compress it, of course it compresses because it, just repeats at some point. But for him it didn’t matter, right? He’s got enough random numbers here to start. And so he says the following. Which you can read.

Don: Anyone who considers arithmetic…

Adam: Arithmetical?

Don: Yeah. No, it’s not mathematical though, it’s arithmetical.

Anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin. For, as has been pointed out several times, there is no such thing as a random number. There are only methods to produce random numbers, and a strict arithmetic procedure, of course, is not such a method.

Scan of von Neumann's 1951 paper: the title block and the paragraph beginning Any one who considers arithmetical methods of producing random digits is, of course, in a state of sin
Said at a 1949 symposium, written up by George Forsythe, printed in 1951. John von Neumann, "Various Techniques Used in Connection with Random Digits".

Adam: So he’s saying it’s impossible, to produce a truly random number. As far as our wagering goes, it feels like John von Neumann is on my side.

Don: But he doesn’t just say you can’t produce one, he says there’s no such thing as a random number.

Adam: I mean, he words it nicer, but it does sound a lot like our Kevffinn guy.

Don: Anybody else is fraudulent.

Adam: Yeah. So he said this to a room of colleagues and, yeah, somebody wrote it down when he was explaining his methods for calculating it. But he wasn’t saying that he was doing something wrong necessarily, right? He’s saying, “I know what I’m doing,” right? These neutrons are supposed to be random. But I don’t care, it doesn’t matter that we don’t have truly random numbers in Doom because nobody’s noticing. And von Neumann’s saying like, “Yeah, these aren’t really random numbers, but like the atom bomb doesn’t know that.”

Don: It’s sufficient for our…

Adam: Yeah.

In 1955, You Could Buy a Book of Random Numbers

Adam: So things get more complex from there because, you know, John von Neumann had, like, a early computer trying to do these calculations for the atom bomb, but, there becomes more and more need for random numbers. And so in 1955, you could actually buy a book of randomness. It was called A Million Random Digits with 100,000 Normal Deviant, Deviates?

Don: Deviates, yeah.

Adam: And so this was built by RAND, the government organization that people say stands for Research and Not Development, but I don’t think that’s what it actually stands for. But they needed random numbers. They needed a system better than John von Neumann.

Title page of the 1955 Free Press edition of A Million Random Digits with 100,000 Normal Deviates, by the RAND Corporation
The 1955 title page. A million digits from an electronic roulette wheel, sold as a book. RAND Corporation, via the Internet Archive.

Adam: So they actually built something like a roulette table. They put a ball in and spin it and then see where the number comes out. And so they’re saying, like, “These are truly random,” right? They’re not made by some weird process, von Neumann didn’t just write them down. Carmack didn’t just create them. It’s like, “These are truly random. We did the thing…

Don: This you know, a million times.

Adam: Yeah. Which would take a while. It’s not like they…

Don: They paid some guy to keep spinning things. He was like, “Yeah…

Adam: Just to keep spinning it?

Don: Every day, 9:00 to 5:00, get in there and spin, spin, spin that little roulette table. Get us the numbers. Or well, they get a whole bunch of people to spin. A whole bunch. And then write them down, and then they collate the whole thing.

Adam: ‘Cause it’s not like they had a camera. Like today you could do a overhead camera and optical recognition or something. Like somebody had to spin this.

Don: This is 1955.

Adam: Yeah. And so my mom, when she was doing her master’s in, psychology. So they are assigning people to different groups, A and B to do some sort of test. How do they assign them? So back then she said this is what they have. They have like a book of random numbers, and when you have a new person coming in, you, pick one of the things. You’re like, “Oh, this is below 50, you’re in group A. This is above 50, you’re in group B.”

Adam: So that’s why they needed books like this. But this is basically a very large and old version of Doom’s list of random numbers, right?

Don: It’s just a lot bigger.

Can Anyone Crack Python’s Random Numbers?

Adam: Okay. Okay, so then going further, like today, we just have random number generators on our computer, right? Like we have Python’s random number generator. So here’s random numbers from Python. And if we look at the histogram…

Don: Yeah, it looks pretty random.

Adam: Yeah. And if we count it, we’ll run the statistical analysis. Yeah, it says it’s uncorrelated. So it seems satisfactory, our statistical tool says. We tried to zip Python random numbers, cannot zip at all. Right. That makes sense. We can do this predictor. So I built this predictor. So the predictor is the same as the game you were playing. It’s gonna try looking at the history of the numbers…

Don: If there’s a pattern, it’ll be able to guess.

Adam: Yeah. So it wasn’t able to guess. Its guess rate is, like, 40.4…

Don: 0.4%.

Adam: So random chance would be 0.39, and it got 0.4. Okay, so far…

Don: Pretty close.

Adam: This looks unbreakable, right? We could do your digits of pi and I think it will shake out the same, right? So this is going to try to guess the numbers by using a cracker. And so we give it 600– we give it the first 624 outputs, and then it’s able to guess all the ones that come after it. So the Python randomness has been cracked. This is like we’ve predicted what comes next.

The Count instrument on Python's random: ent output with entropy 7.997 bits per byte, chi-square p 0.26, mean 127.775, Monte Carlo pi 3.158, serial correlation −0.004; verdict survived
Python's generator against the classic five numbers. All five in the fair-dice band. These are the tests RANDU passed for a decade.

Don: Oh, okay. So it’s like an upgraded predictor from the previous step?

Adam: So the way this predictor works has to do with John von Neumann’s point. So all this does is looking at your sequence of numbers, it tries to guess what sequence it is. Okay, so Python’s random number generator, it uses something called the Mersenne Twister, specifically MT19937. So it has just an algorithm that it uses to generate these random numbers.

The Crack instrument on Python's random: watched 624 outputs, reconstructed the generator state, then predicted the next 20 numbers, all correct
The Mersenne Twister has 624 words of state. Watch 624 outputs, undo the tempering, and you are the generator. Python random.

Don: So this thing basically finds the algorithm and now it can predict.

Adam: Yeah, the thing is that the cracker knows that that algorithm exists, and so given a sequence of numbers, it can just check to see if it’s in the random sequence it would expect is generated by that algorithm. And then it backs it out.

What About Pi? Predicted by Whom?

Don: Yeah. But so what about pi though?

Adam: What about pi, right?

Don: If you can predict pi, you’ve solved it.

Adam: But pi is solved, right? We know what the digits of pi are.

Don: Yeah, but there’s been no pattern to it, so, like, it would be impossible to predict it.

Adam: Well, let’s try our cracker on. But it was able to guess. So given a bunch of digits, it identified that they were part of pi, and then it can produce the ones that follow.

The Crack instrument on the digits of pi: it names the sequence as pi and predicts the next 20 values, all correct
Pi (here in base 256) passes the histogram, the statistics and gzip. Then the cracker recognizes it and recites what comes next.

Don: Yeah, ‘cause it knows what pi is.

Adam: So the numbers aren’t surprising because it knows what’s gonna come next, right? Given any sequence, once it identifies that the digits are the digits of pi, it can always tell what the next one’s gonna be ‘cause it knows it’s the next digit of pi. There’s something super interesting, right? What does it mean for something to be random? Because John von Neumann is like, “Hey, this is random enough for my calculations.”

Don: It can’t be– I guess it can’t be reasonably or consistently, predicted.

Adam: Predicted by who is the question.

Don: I mean, to win the bet, it’s your program.

Adam: Yeah, yeah, that’s true. That’s true. ‘Cause he didn’t care that his numbers weren’t random because he was saying, like, “They work for the calculation. They’re random enough for my neutron calculation.” If, you know, they were lottery numbers, then it wouldn’t be good, ‘cause if somebody figured out the sequence, they could…

Don: Win every time.

Adam: Okay. So humans can’t produce a random number, although Don thinks maybe with some training he could.

Scoreboard at the halfway point: pi, middle-square and Python's generator added, all condemned
Halfway. Every formula we tried fell to the same thing: a judge who knew the formula. Python's generator is the Mersenne Twister.

Don: No. I think that I was getting close.

Adam: Yeah. You were getting better, like for certain, right? Von Neumann’s point is like a formula, an arithmetic formula can produce things that seem random, but anyone who knows what the formula is, they immediately become non-random to that person ‘cause they know how to get it.

Don: Obfuscation. It’s like random only until because they don’t know how it’s made, but once they do, then it’s no longer…

Adam: Yeah. Exactly, right? Okay, so let’s go further.

Does Your iPod Play Favorites?

Adam: January 2005, the iPod is the most beloved gadget on earth, and its owners are convinced that shuffle is playing favorites. It’s the same complaint as that guy had…

Don: Tetris. Box, yeah.

Adam: With the Tetris thing. They’re like, “Hey, I put this on random and it keeps playing the same, Joni Mitchell song.” And people got mad. It became, like, an article in Newsweek, where Newsweek was like, “Does your iPod play favorites?” And then Apple went on the record, right? Steve Jobs said, “Random is random.” If we’re saying whether something’s random or not has to do with the perceiver, people are just not… People are bad judges of whether it’s random, but they also get upset. Here’s a quote from Steve Jobs. You can probably read:

Don:

You know, we’ve gotten a lot of people that say our shuffle’s not random. Well, it really is random, but sometimes random means you’ve got two songs from the same artist next to each other. It just happens randomly sometimes, and that’s so we- that’s … And so what we’ve added is Smart Shuffle to actually make it less random if you want. Even though people will think it’s more random, it’s actually less random.

Steven Levy's Newsweek column Does Your iPod Play Favorites?, with Apple's engineers insisting Random is random
In January 2005 Apple told Newsweek "Random is random." That September Jobs shipped Smart Shuffle. Steven Levy, "Does Your iPod Play Favorites?", Newsweek.

Adam: I like Steve’s being a, pedantic.

Don: Yeah.

Adam: He’s like, “This is actually worse, just letting you…

Don: Just letting you know, it was actually random. You guys want s- you don’t want random, you want… That’s less…

Adam: Yeah. And then it happened with Spotify too, like years later. Spotify got the same complaint and had to change their random playing. But I was telling you about how when I was a kid, I figured out that my random on my CD player had a pattern. Yeah.

Don: Yeah.

Adam: It wasn’t that it always did the same songs. It always had the same order of like, if it played this song, then the song that followed it was always a certain one, and then a certain one, and a certain one. So it’s like it had made a new ordering of the tracks, but it just picked a random spot. It’s like Wolfenstein. It’s like it picked an offset and randomly went around.

Don: Yeah, and then you figured it out.

Adam: Yeah. But it was easy to figure out ‘cause you listen to a CD too much and it’s on random, and you always hear the same song after. You’re like, “Hmm, then…

Don: Random.

Adam: It’s…

Don: I mean, in that case, it really wasn’t random.

Adam: Yeah. But I don’t know, I just had too much time on my hand ‘cause I ended up figuring out the order for various CDs. ‘Cause it was a different order on every CD. Probably they used the time, the length of the CD as, like, an offset seed, but that meant that for that CD you always got the same random.

Don: It always was the same.

Adam: And so this happened a whole bunch of times in World War I… No, sorry, in World War II, which is 1944, people were getting bombed in London, and certain buildings got bombed and certain other buildings didn’t, and people got all conspiracy-minded. If everybody’s house got blown up except for yours, you know, they would think like, “Oh, Don’s the German spy. That’s why his house didn’t get hit.”

Adam: And it led to legitimate problems until, like, an actuary did the whole statistical trick that my little thing was doing and saying like, “No, actually, these are completely random who’s getting hit. It doesn’t mean Don’s bad.” Yeah.

Adam: And then this happened, like, a million other times, right? I think you mentioned this, XCOM 2 on the easiest difficulty setting of XCOM, the displayed odds were actually multiplied times one point two. So it’s the reverse of what you said. Your original complaint was you would miss too much, but they’re saying they actually had to give you a better probability than it said.

Don: They probably put that in because so many people were so mad. If you had 98% and it missed, it could’ve been completely random, right, that you missed, but you feel like the game is out to get you.

Is a D20 Roll Random? Ask Persi Diaconis

Adam: Yeah. But this happens all the time, right? Just our perception of things, isn’t very good. Okay. But I mean, that doesn’t have anything to do with our contest really. But what we’ve done so far is… I mean, we’ve kind of run out a little bit on computery stuff, right? So let’s go to physics. Okay. Physical randomness, I got here a D20, so just roll it.

Don: Well, yeah, so physical randomness is like dependent on a lot of other factors, like rolling a dice. Like is this dice weighted? Equal on all sides? Seven.

Adam: Seven. Okay, roll it a couple times. 19.

Don: That was a good one. That was a… 19 was a good roll. A seven again.

Adam: Seven. So I did some random, dice rolls with that earlier. We’re gonna test them out. We could run the statistical thing, and it says, “All 20 faces in the fair band.” It doesn’t zip well. Let’s see if our predictor… Okay, so nothing out of my physical dice rolling can be predicted.

Adam: But there’s people who looked into this, right? There’s this guy called Persi Diaconis, and he ran away from home at 14, and he became a sleight of hand magician. And then later he became a Stanford statistician. And he got really interested in this idea of coin flips. And so he built a machine to flip coins. So here’s one of his quotes. You can read it.

Persi Diaconis, smiling, grey curly hair
Persi Diaconis, who left home at 14 to do magic and came back a statistician. Photo: Steve Castillo.

Don: With careful adjustment, the coin started heads up always lands heads up 100% of the time. We conclude that coin tossing is physics, not random.

Adam: So it’s kind of like this idea that, flipping a coin or, like, rolling a dice is chaotic. But that doesn’t mean it’s actually random, right?

Don: Yeah. I mean, it’s kinda like when you’re younger and you have a six-sided die, and you’re like, you figure out if you start it here on this part of your hand and it flips one, two, three, you’ll go on six every time.

Adam: Yeah, which means that these physical things might not be truly random, right? We count them as random because we don’t know what’s gonna happen. Doesn’t that hurt the physical aspects of generating random numbers? Like, so we can’t use a dice.

Don: Well, no, I don’t think anybody’s suggesting using dice to supply a truly random number.

Casino Shufflers and a Vegas Slot Machine

Adam: So then, the same thing apparently is true of cards. How many times do you have to shuffle a deck for it to be actually random?

Don: It depends on who’s shuffling it.

Adam: Yeah, I mean, I’m a pretty crappy shuffler.

Don: You can get, the shuffle machines from, like, Vegas.

Adam: And they do it definitively?

Don: Yeah.

Adam: Diaconis, the same guy with the coin flip, he looked into cards, right? He went to a casino machine company and got one of their shufflers and asked them how many times they use it to shuffle, a fresh deck of cards before they send it to the casino. And they said that they had already tested it on a single shuffle, and it seemed sufficient. So he ran a test, and he found that actually, no, there was still patterns left, that they weren’t shuffling it sufficiently. Here’s a quote from him.

Don: We were able to show that a knowledgeable player could guess about nine and a half cards correctly in a single run through a 52-card deck. For a well-shuffled deck, the optimal strategy gets about four and a half cards correct. This data did convince the company.

Adam: There was, like, a thing where this Russian guy was cashing all this money out of these slot machines in Vegas, and they couldn’t figure out what was going on. And then it turns out that he had somehow figured out what the pseudo-random number generator was, and he would record…

Don: Your, like your Discman. You figured it out. Yeah.

Adam: Yeah. He would record, you know, the machines playing, and then he would be able to see, it’s like if you watch it enough. Yeah, exactly like the Discman, and probably more complex, but if there was a certain pattern, he would know, like…

Don: Now I know what the next number is gonna…

Adam: Yeah.

Don: Yeah.

Adam: That guy showed that clearly you can predict coin flips, you can predict dice rolls. You just need enough information.

Don: But I mean, for the purposes of not being able to predict the number, it’s random.

Adam: That’s right, right? If we consider the perspective of…

Don: That’s why we needed the definition of random. So if the definition of random is that you can’t predict it…

Adam: Then it wins. The physics seems undefeated, but…

Don: I mean, if anybody has all the information of the entire universe down to subatomic particles and they’re running it all in a simulation, then yeah, you’ll know exactly the outcome of everything that ever happens. You’re not gonna ever have all that information, so everything’s going to appear random to you.

Where Does urandom Get Its Randomness?

Adam: But if it were, and this simulation starts, you know, with some random seed just like your Minecraft level generating. You know, I rolled those dice and I got random numbers. But if you use the same seed and played through all of reality and everything was completely deterministic, that other Adam would get the same numbers as well. And so it would be random for both of us Adams, but to an observer from the outside, it’s not random at all.

Adam: So I think, this is the only source on the computer we haven’t tested so far. The operating system can hand you, if you make a system call, back a random number. So it’s like, where does the operating system get its randomness? Well, let’s try it. So this is /dev/urandom, except I’m doing it in Python, so it’s os.urandom. And so it generates all these numbers. It generates a lot of them.

The Count instrument on os.urandom: entropy 7.9971 bits per byte, chi-square p 0.37, mean 127.871, Monte Carlo pi 3.109, serial correlation −0.001; verdict survived
urandom on the Count instrument. The numbers look the same as Python's. The difference is what's behind them.

Adam: If I look at a histogram, I don’t know, seems random. A lot of times if you just can graph something in a way humans can perceive, we’re really good at spotting patterns. So this, I don’t see any patterns here, right? Like it’s just random.

Don: No, it looks like a cube of stars.

Adam: Yeah, and the cube is just the space of possible values, right? Put into three dimensions. Looks random to me. We can run our statistical thing. It says the numbers are uncorrelated. Survived. Okay. We can try to zip our urandom data. It does not zip at all. Okay, we could try to predict it. So yeah, it says chance blind, so it can’t be predicted. We can try our cracker. It says no.

Don: It reseeds from hardware noise.

Adam: It says, “Extremely fine-grained timing variations in hardware, device and system activity, other platform-specific entropy sources.” Huh. So it says it’s based on a relatively small amount of genuine entropy mixed with some cryptographic machinery that expands it. Okay. We have true randomness though, right? Or something like it.

Does IBM’s RANDU Pass the Human Test?

Adam: So before urandom existed, but after the book of One Million Things, IBM, came up with a subroutine for generating random numbers, which was called RANDU.

Don: RANDU.

Adam: Yeah, so it was distributed on IBM’s scientific subroutine package, on systems such as System/360. It’s like the equivalent of what I’m doing, in the ’60s. So I have its data here. So this is RANDU. I mean, it also looks pretty random.

Don: Passes the human test.

Adam: But…

Don: Oh, wait a minute. There was a pattern there.

Adam: Is there a pattern?

Don: Yeah, it was. They all, it all went diagonal lines. See?

Adam: We found it.

Don: Yeah, there you go. The cube, the cube…

Adam: So it looks totally random until you’re at ex-

Don: You get the right angle and then they’re…

Adam: Exactly the right angle…

Don: And then they’re all lines.

Adam: Then you can see all the patterns in it. So it seems like it’s totally random data, but there’s actually 15 specific, planes of random numbers.

RANDU's output in 3-D. From most angles it's fog. From one angle every point lies on one of 15 planes, because xn+2 = 6xn+1 − 9xn (mod 231). RANDU.

Don: They look like pages slotted in there.

Adam: In 1968 after people using this, this guy wrote a paper which he called Random Numbers Fall Mainly in the Planes, which he was like, “Dude, your random numbers are broken. You said they were random. We all trusted them. They’re random. We’re using them for everything.” Here’s your quote.

Don:

RANDU was, alas, the generator actually used on such machines in most of the world’s scientific computing centers for more than a decade.

First page of George Marsaglia's 1968 PNAS paper Random Numbers Fall Mainly in the Planes
The paper that named the flaw: George Marsaglia, "Random Numbers Fall Mainly in the Planes," PNAS (1968). The "alas" verdict read above is Donald Knuth's, from The Art of Computer Programming, Vol. 2.

Don: Oops.

Adam: The whole problem up until this point that we’ve been struggling with, as well as, the people historically dealing with this is, what does it mean for something to be random.

Adam: So after that happened, I mean, a couple decades after in 1982 there was a breakthrough. Someone tried to write down, a definition that would matter. And so it all happened at the same conference. There was this guy named Yao, and he proved that you could define randomness by what a computer can predict. And at the same time, Blum and Micali built a generator to that standard.

Page 852 of Blum and Micali 1984: the definition of a polynomial-size statistical test, and THEOREM (Yao): a collection passes the next-bit test if and only if it passes all polynomial-size statistical tests
Yao's result, as Blum and Micali print it: a sequence that beats every efficient next-bit guesser beats every efficient test there is. One test stands in for all of them. Blum and Micali (1984), p. 852, citing Yao, FOCS 1982.

Yao’s Definition, Candyland, and the Lunch Bet

The randomness of an event is relative to a specific model of computation with a specified amount of computing resources.

Blum and Micali, 1984, page 850: the italic line The randomness of an event is relative to a specific model of computation with a specified amount of computing resources
The line, set in italics on the first page of Blum and Micali, "How to Generate Cryptographically Strong Sequences of Pseudo-Random Bits," SIAM J. Comput. (1984). Yao's theorem, that passing the next-bit test means passing every efficient test, is two pages later.

Adam: The thing I got away from what they were saying was randomness is in the eye of a beholder. Like it’s almost a adversarial process, I present to you numbers. If you can guess what they are, they’re not random. So it comes down to who the adversary is. It’s a lot like our compression story. If you can predict the next number in my sequence, then it’s not random.

Don: Yeah, if we’re playing a game of D&D, when you roll the D20, none of us at the table can predict what the next number is gonna be. So it suits the purpose of being random.

Adam: Right?

Don: But if somebody else sits down and they know exactly what each roll’s gonna be, then, it’s not random.

Adam: Candyland, are you familiar with this game?

Don: No.

Adam: So Candyland, super interesting, not a fun game that you should play, but, you know, it’s like the game of Life. You move throughout the board, but an interesting thing is, you shuffle cards, and then the cards are like your dice roll. So you flip over a card and it says move three…

Don: Oh, okay.

Adam: Flip over a card, it says move one. You know, I look at the cards and I read through them, I know exactly how the game is gonna play. In theory, I could simulate it through and know what’s gonna happen, right? But to you, who hasn’t seen the cards, it’s random. But to me, who’s read all the answers, it’s no longer random.

Don: I’m always looking for recommendations for games that aren’t fun.

Adam: Yeah. I mean, don’t play that. It’s…

Don: Play this game. It’s not fun.

Adam: So what does it mean for something to be random, I guess is the answer, or is the question. One idea is that it just means that nobody who’s involved can predict it, right? But then how do we determine our bet?

Don: Well, like, I believe then we defined random as…

Adam: As my program.

Don: As your program.

Adam: Yeah.

Don: Beaten several times.

Adam: Yeah. I’m screwed.

Don: Why it’s important when making bets with Adam, you have to define the parameters first.

Adam: Yeah, exactly. But we actually agreed to bet before we came up with what we’re betting on.

Don: Yeah, which I think was also dirty pool.

Adam: Yeah. So yeah, I mean, I’ll concede that, you won in terms of my oracle, right?

Don: But like the higher level question of is a truly random number possible?

Adam: Is it answered or is it unanswered? What do you think?

Don: I think given sufficient information, everything can be predicted.

Cloudflare’s Lava Lamps and random.org

Adam: But the key is the external noise. If we agree that the world, the physical world is kind of deterministic, but it’s just too big of a calculation to be able to ascertain, right? And so by bringing in this stuff from the outside world, you’re introducing this chaos that makes it unable for us to predict. So Cloudflare, in their San Francisco offices, they have this wall of these lava lamps, and they have like a camera that’s pointed at it, and they use that as their source of random for their encryption.

Don: I mean, it’s a little bit of a gimmick, but I…

Adam: It’s totally a gimmick, right? They don’t actually need that, but it gets across this idea that they’re taking data from the physical world, right? Like, in order to know, you know, you need to simulate a lava lamp. And it’s not impossible to simulate a lava lamp. But the initial conditions…

The wall of lit lava lamps in Cloudflare's San Francisco lobby
The wall in Cloudflare's San Francisco lobby. A camera photographs it and the pixels seed their generators. Photo: HaeB, Wikimedia Commons, CC BY-SA 4.0.

Don: There are so many problems with that.

Adam: Lead it chaotic. What’s the problem?

Don: If having a camera, like what if the lights go out or what if the camera malfunctions? Do they have like a backup secondary camera? What if the, one of the lava lamps, you know, stops working or something like that? What if somebody breaks in and steals some of the lava lamps?

Adam: I mean, you can go in and see it, so I mean, you could take a picture of it and reconstruct, I guess, if you… But it’s just one source of entropy, right?

Don: Too, yeah, too chaotic for us to simulate.

Adam: But that doesn’t mean it’s not possible.

Don: It’s not possible. Yeah.

Adam: I think it’s our best bet we have so far out of all of these things, right?

Don: No, atmospheric scattering.

Adam: Atmospheric scattering. Okay.

Don: So there’s a site that’s supposed to use that data to generate a random number if you needed it, random.org. Yeah, it comes from atmospheric noise. Service has existed since 1998 and was built by Professor Mads Haahr of the School of Computer Science and Statistics at Trinity College in Dublin in Ireland.

Adam: Until, Call of Duty Mobile starts using that, you know, Kevffinn’s not gonna be happy. If there’s not, a dude whenever I open my loot box who’s, like, rolling a D20 somewhere and then writing it down…

Don: There’s real-time statistics that you can get.

Is random.org More Random Than urandom?

Don: Then there’s an information entropy. Information entropy gives an indication of how difficult it is to predict what the next bit will be based on the bits you already may have seen.

Adam: That’s my oracle test.

Don: Then there’s frequency monobit test.

This test is part of NIST recommendations. The graph shows whether the numbers of zeros and ones produced by the generator is as close to fifty-fifty as you would expect from a truly random sequence.

random.org's Frequency (Monobit) Test panel: a histogram of the share of ones per block, with the explanatory text
random.org's running monobit check on its own output, the same count Don's F/J presses were held to. random.org, Statistics; the test is §2.1 of NIST SP 800-22.

Adam: That’s what you failed with your FJ?

Don: Well, I was getting better.

Adam: Well, so far we’ve tried all of these, and my urandom works, passes them.

Don: Well, we didn’t run ours through all of the additional tests that they use. There was like 20 tests that they have there.

Adam: Yeah, but I would be surprised if we didn’t pass most of those. Like we passed the hard ones I think. It’s hard to imagine the ways in which it’s better.

Adam: It’s better in provenance-wise, ‘cause I can say, like, if I’m picking a random number and I use that site oh, look, they have all this data, and they got it from the atmosphere, whereas if I just get it from urandom on my computer, it’s less clear to say where it’s from. They have more legitimacy. They can stamp on it like it came from a radio wave.

Adam: But that doesn’t mean it’s more random because I think there’s no observer, that we’re aware of that could predict ours but couldn’t predict theirs.

Don: Oh, I see. Yeah, until you find that person.

Adam: When you find that person and they’re like, “No, there’s a vulnerability on the Mac and actually it’s not truly random,” and whatever, then there’s a difference. But right now, no, there’s no measured difference that anyone could find, right? Yeah, which is why randomness is not a property of the number, right? It’s a property of, the person trying to guess it, yeah, that’s why this person, Dylan, on Hacker News, I think they sum it up well.

Don: There is actually no such thing as a random or not random number. There are only random and not random generators.

Hacker News comment by Dylan16807: there is no such thing as a random or not random number, only random and not random sources
Dylan16807 on Hacker News, December 2012, on "What does randomness look like?"

Adam: But the all caps guy at the beginning and the blackjack poster and the guy who was angry about XCOM, and even von Neumann, right? They’re all kinda getting at the same idea randomness is a process.

Don: Yeah, the property of randomness isn’t inherent in the value. It’s derived from the observers of the value. Yeah, so if, you know, you can’t predict whether you’re gonna hit or miss a shot in XCOM, that’s random enough. It…

Adam: Yeah. Random enough for your purposes.

Don: Doesn’t have to be a true random. Like, I feel that a lot of these comments go into the comment section, and they start pulling out these high, concepts of randomness. It’s like, “Well, true random numbers don’t exist.” It’s like, but they can exist for the purposes of the video game, and they have been implemented to that capacity.

Random to Whom?

Adam: Okay, so here’s what we’ve learned maybe. Randomness is never a property of numbers, so there isn’t really such thing as a random number, right? Seven isn’t random. Nor a string of numbers. Randomness is sort of a contest, right? You have this generator on one side trying to produce things, and then you have something else trying to guess them. So if it, can’t predict them better than chance, then that number sequence is random to that predictor.

Adam: That’s why everything kind of fell apart when you get into the details, right? It depends what you’re judging with. Every judge in my little program that beat something just knew something more.

The final scoreboard: twelve datasets against five instruments; only os.urandom is undefeated
The full rap sheet. Each ✗ is a judge that knew one more thing. What's left undefeated is undefeated only by the judges we had. random(7) describes where urandom gets its seed.

Adam: RANDU, which was IBM’s thing, it looked completely flawless, right? So for everybody using those, those were in fact random numbers until somebody was like, “Wait a minute. What’s going … I’ve predicted them…”

Don: There’s actually just 15 sets of a pattern here, yeah.

Adam: Yeah. And at that point, for that, observer, he understood enough of the process to be able to predict the numbers and they become not random. So it’s not really about whether something’s random. It’s about, like, random to whom, right? Is it random to you with your loot box? You know, John Carmack’s numbers worked fine.

Adam: The guy at the beginning Kevffinn, with all his caps, he, said computers can’t create random numbers. Well, I guess that’s true because our urandom was the winner, but it didn’t produce the random number. It’s using some sort of sensor to get some sort of external, information, right?

Don: Yeah. I think that it’s 100% possible that Call of Duty Mobile could generate a random number insofar as nobody can predict what the outcome will be.

Adam: Yeah. I guess I lost the bet. We did produce a random number.

Don: Yeah, it was random to you.

Adam: And it’s random to my program. Yeah.

Don: But was it truly random? Probably not.

Adam: Yeah, if the world is deterministic, then somebody could predict it. I will buy you lunch. Where do you wanna go? That was the show. Thank you for listening. Thanks for coming over, Don. Hopefully it wasn’t too random.

Don: No. No, it was predicted, entirely predicted.

Support CoRecursive

Hello,
I make CoRecursive because I love it when someone shares the details behind some project, some bug, or some incident with me.

No other podcast was telling stories quite like I wanted to hear.

Right now this is all done by just me and I love doing it, but it's also exhausting.

Recommending the show to others and contributing to this patreon are the biggest things you can do to help out.

Whatever you can do to help, I truly appreciate it!

Thanks! Adam Gordon Bell

Support The Podcast
Select an episode