Here’s a fun idea to think about.
For this post, I’m going to use Nintendo Entertainment System (NES) games as examples. This is because NES game code is very tiny compared to modern file sizes.
So, I wanted to know what’s stopping me from creating a script and literally generating every NES game ever created? Let me explain.
First of all, what is a NES game made of?
Well, NES ROMs (Read Only Memory, aka. game code) contain lots of instructions that are already at the lowest programming level; machine code. Each byte in the NES ROM gets executed instruction after instruction directly by the NES CPU. Meaning there is no conversion or compilation required. It is immediately processed by the CPU. Depending on the value of the byte, the CPU may do something important or not (it’s usually important).
Here’s the first few instructions in the ROM code of Super Mario Bros. for the NES.
Okay, cool. So with our modern computers, couldn’t I just make a script that randomly generates thousands of bytes, dump it into a file, and plug it into a NES? Yes, you could! Would it be a working game? Probably not. This is because there are soooo many possible combinations.
Wait, how many combinations are there?
Okay, let’s say we wanted to generate a version of Super Mario Bros. where Mario has a green hat instead of red. So, Super Mario Bros. for the NES is around 32KB in size, which is 32,000 bytes. Okay, so piece of cake, just randomly change each byte until Mario has a green hat, simple! Hold on, each byte has a range from 0 to 256, math formula: 2 to the power of 8 (2^8). So to calculate the amount of combinations in a single 32KB file, we just need to do that… 32,000 times.
(2^8)(2^8)(2^8)(2^8)(2^8) … 31,995 more … = 2^256,000
Meaning, each time your program generates a new file, the chances it’ll generate the exact copy of Super Mario Bros. where Mario is wearing a green hat is: 1 in more atoms in the observable universe TIMES TWO-THOUSAND!
So, while you can write a script to do this and generate every game Nintendo ever created, you’d also generate every game Nintendo never created.
It’d also take you longer than the whole universe’s existence to generate one specific game.