# What is the probability of 4?

I would like to know with what probability the number 4 appears in the grid of the game 2048. As well, is this probability the same at the beginning? I tried to find the original game's source code, but I did not succeed.

• This strip would've been funnier if the repeating number was 4, but I remembered wrong...
– l I
Jun 5 '14 at 18:49
• xkcd.com/221 where it is 4 Jun 5 '14 at 19:45
• @z' Only `9`s appear. Only powers of two can join. Task: Score any points.
– yo'
Jun 5 '14 at 23:43
• @mmatthews that was the one, i got my comics mixed up
– l I
Jun 6 '14 at 0:16
• 100% probability, according to xkcd Jun 6 '14 at 13:50

Extracted from the source code (line 71) :

``````var value = Math.random() < 0.9 ? 2 : 4;
``````

`Math.random()` returns a number between 0 and 1. This code can be read as follows : Is the pseudo-randomly generated number strictly less than 0.9? If yes the tile value is 2, if no the value is 4. Assuming `Math.random()` generates numbers with uniform probability over (0,1), the code implies a 90% chance of a 2, and 10% chance of a 4.

As for your second question: Yes, the probability is the same at the beginning. When the game starts 2 tiles are generated and their value randomized with the code above.

i believe its 10% for a 4 and 90% for a 2

• You're not wrong necessarily, but without providing any kind of source, it's just speculation. Jun 5 '14 at 22:50

I played a game and wrote how much 2 and how much 4 appeared. There were 326 times number two and 56 times number 4. So it should be abaout 17% more or less. The variation on the percentage shouldn't be more than 3%. So I would say it's between 14 and 20 percent.

I personally think that it should be 1/6 but that's just speculation...

If you want to be more precize, then just play a lot of game and wrote what you got.

I usually get a 2 65% of the time and 4 35%. It can vary, I can sometimes get alternations between the two. Sometimes the probability of the two actually swaps. You can never tell.