Random Game

Optimal strategy calculator for number-guessing games

Screenshot of Random Game
Random Game.

There's a common party game or icebreaker where someone picks a random number in a range, say 1 to 100, and everyone guesses. Closest guess wins. If you're the only player it's just binary search: guess the midpoint, adjust based on feedback. But when other people are guessing too, the optimal strategy changes. You don't want to guess the midpoint of the full range. You want to guess the midpoint of the largest unclaimed region, because that's where you have the highest probability of being the closest.

Binary search visualized on a sorted array
Binary search narrows a range by half with each step. The same strategy applies to number-guessing games. Wikimedia Commons

The algorithm

You enter a minimum and maximum to define the range \([a, b]\). As guesses are made (yours and other players'), you enter each one. The app collects all known numbers: the bounds and every guess so far. Let the sorted partition points be \(a = x_0 < x_1 < \cdots < x_k = b\). The app computes the gap \(g_i = x_{i+1} - x_i\) for each consecutive pair, finds the largest gap \(g^* = \max_i g_i\), and recommends guessing the midpoint of that interval.

If the target is drawn from a uniform distribution on \([a, b]\), the probability that the target falls in interval \(i\) is \(g_i / (b - a)\). The strategy of bisecting the largest interval is greedy: each guess maximally reduces the length of the longest interval, which minimizes the worst-case distance between any point and the nearest guess. After \(n\) rounds of optimal bisection on \([0, 1]\), the maximum gap is \(2^{-n}\), giving logarithmic convergence in the single-player case, exactly matching binary search.

With multiple players, the known guesses act as additional partition points contributed by opponents. The strategy adapts by always targeting the largest remaining gap. If the range is 1-100 and someone guesses 30, the two regions are [1, 30] and [30, 100]. The second is larger, so the optimal next guess is 65. If another player then guesses 80, the regions become [1, 30], [30, 80], and [80, 100]. The largest is [30, 80], so you guess 55.

Probability density function of a continuous uniform distribution
Probability density function of a continuous uniform distribution. Wikimedia Commons

When this actually matters

In practice, most people guess round numbers. They cluster around multiples of 10 and especially around 50. If you've ever played this game in a group, you've seen three people all guess numbers in the 40-60 range while the extremes go uncovered. The solver exploits this by always targeting the largest open gap, which tends to be far from the popular guesses.

I originally built this for a specific situation: a recurring office game where the prize was picking the lunch restaurant. I kept losing because I was guessing "intuitively" and competing with other people's intuitions for the same part of the number line. After switching to this strategy I won noticeably more often.

Implementation

The UI has three input fields (min, max, latest guess) and a "GO" button. The recommended guess displays below. It's vanilla JavaScript and HTML, no dependencies. The entire logic is about 20 lines of code.