---
title: 'How 2048 picks the next tile · Reverse Engineer Projects showcase'
url: https://reverseengineerprojects.com/showcase/tile-spawn/
---

[Home](https://reverseengineerprojects.com/) / [Showcases](https://reverseengineerprojects.com/showcase/) / 2048 tiles

  Web game · One line

# How does 2048 pick the next tile?

  After every move a new tile appears. Players argue about how often it is a 4. The game's script settles it in one line.

## Ask your agent

    Your coding agentCopy

      ›Use REP on the 2048 game page open in my Chrome. Where does a new tile get its value, and how often is it a 4? Show the code.

    REP lists the scripts the page loaded and searches them by what they do: the function that runs after each move and writes a value into an empty cell is the spawner.

## The rule in the game's script

    game_manager.js · addRandomTile[Source, lines 69-76 ↗](https://raw.githubusercontent.com/gabrielecirulli/2048/478b6ec346e3787f589e4af751378d06ded4cbbc/js/game_manager.js)

```
GameManager.prototype.addRandomTile = function () {
  if (this.grid.cellsAvailable()) {
    var value = Math.random() < 0.9 ? 2 : 4;
    var tile = new Tile(this.grid.randomAvailableCell(), value);
    this.grid.insertTile(tile);
  }
};
```

    A new tile is a 2 nine times in ten and a 4 one time in ten, on any empty cell with equal chance. The game starts with two such tiles (startTiles = 2). Nothing depends on your score or the board: the odds never change.

## Spawn some tiles

        Spawn 1,000
        Spawn 1
        Clear

          Tiles0
          2—

          4—

New start

      The same rule as the game. A thousand spawns land near 90 / 10; a single start shows two 4s about one time in a hundred.

## Why it matters

    Strategy guides tell you to plan for the 4. The code says how often: one spawn in ten. A bot that plays 2048 can now weigh every move by the real odds instead of a guess.

    2048 is open source (MIT); the lines above are quoted from its public repository with a link to the exact revision.

  On this page[Ask](#ask)[The rule](#code)[Spawn tiles](#try)[Why it matters](#why)
