I am not sure where I came across the Number Gacha website. It must have appeared at the top of Hacker News, I guess, but I don’t recall. Anyways, I kind of liked the game. Though initially I found the idea of just randomly spinning it quite gambling-like1, it quickly became my go-to game. Instead of scrolling through random feeds, I was doing math problems to get 5 extra spins and opening those number packs with quite a lot of hope. It took me about 51 days, but I got 100% on the game, as you can see from the screenshot below.

Number Gacha collection completed after about 51 days

Now, this could have been the end of things, and I wouldn’t have had to do a blog post had it not been the age of AI and had I not thought that something shady was happening behind the scenes.

You see, very early on I started to notice that the number 6 was appearing more than usual, so I thought, ah, there must be some bias towards the number 6. That was the very first number that I hit level 9 on. But then 32 was the 2nd number I hit level 9 on, so the pattern broke here, which I didn’t like because I was quite certain that there was some special bias. Later, when 42 hit level 9, I was like KNEW IT! but then the next number was 59. 59??!?! It’s not even a good number. Now, I know that it’s a gacha game, so it does have intentional rarity categories for numbers. For example, most primes appear purple and are considered epic, so they are less likely to appear than a number in the common category. But even with that setting, I just felt that 6 was appearing more than it should.

Anyways, this piqued my curiosity, and so that day I just decided that once I got the 100% achievement, I’d dive into the JS code. What follows is basically me using an agent to do some analysis.

Controlled randomness and rarity tiers

Once I had the 100% achievement on lock, I spun up an agent and asked it to review the JS bundle on the website without sharing my theory with it. I didn’t want to say I think there is a bias towards the number 6 and get a reply that started with You are right2. I just wanted to see whether it would find any other bias on its own.

The whole game is a React app3, and the game logic was in a single JS bundle. So the agent just prettified the bundle and did quite an extensive analysis of it. The initial review showed the obvious things that were happening:

  • It uses the browser’s localStorage to, well, store your progress, which is why no account is needed to retain it. The save is just base64-encoded JSON.
  • There was a debug button that allowed you to get the exact number you wanted, but it was only enabled if the host was localhost.
  • It uses Math.random(), whose implementation depends on your browser’s JavaScript engine.

As mentioned before, when you play the game, you clearly see some numbers4 being purple, indicating that they will appear less frequently than, say, a number in the common category. The rarity tiers are as follows:

TierNumbers
LegendaryPrimes that are also Fibonacci numbers: 2, 3, 5, 13, 89
EpicAll the other primes
RareSquares, the remaining Fibonacci numbers, and multiples of 10
CommonEverything left over

Now, this kind of already explains that 6 is one of the common numbers, so it should appear more frequently than rarer numbers, but I just felt it was happening more than it should, if that makes sense.

To create this intentional bias, the results are weighted even though the game uses Math.random(). So randomness doesn’t mean equally likely. It isn’t simply doing this:

js
Math.floor(Math.random() * 100) + 1

It picks a rarity tier first and then picks a number from that tier. The starting weights in the code are:

js
const Rv = { 0: 60, 1: 25, 2: 13, 3: 2 }
// common, rare, epic, legendary

What all this means is that if you open a pack containing numbers from 1–10, the game looks at those 10 numbers as a set of 4 groups:

  • 2, 3 and 5 are legendary.
  • 7 is epic.
  • 1, 4, 8, 9 and 10 are rare.
  • 6 is the only number in the common group5.

Even though this explains part of it and shows that the rarity bias is intentional because it’s a gacha game, I wanted data to back it up.

The bit that keeps giving me sixes

I explored the code further6. When we move from rarity group selection to individual rolls, the pool for a normal roll is 1–100. For a pack, the same function gets a smaller pool, like 1–10 or 91–100. It groups the available numbers by rarity and adjusts the weights. For every tier except the lowest one present, it compares the tier’s weight with the percentage of the pool that belongs to that tier. If the weight is higher, it caps it and gives the excess to the lowest tier.

The function is called Ms() in the bundled code. Here’s a readable JS version of its selection logic. pool contains the allowed numbers, and rarity maps each number to its tier: 0 for common, 1 for rare, 2 for epic, and 3 for legendary.

js
function rollNumber(pool, rarity) {
  const weights = [60, 25, 13, 2] // Common → legendary, in percent.
  const groups = [[], [], [], []]
  for (const n of pool) groups[rarity[n]].push(n) // Group allowed numbers.
  const tiers = [0, 1, 2, 3].filter(t => groups[t].length > 0)
  const lowest = tiers[0] // Lowest tier actually present, not always common.

  for (const tier of tiers.slice(1)) { // The lowest tier is NEVER capped.
    const share = (groups[tier].length / pool.length) * 100
    const excess = Math.max(0, weights[tier] - share)
    weights[tier] -= excess    // E.g. one epic in 10 numbers: 13% → 10%.
    weights[lowest] += excess  // Its spare 3 points go to the lowest tier.
  }

  let draw = Math.random() * 100
  let selected = lowest // Missing tiers leave unused chance: it lands here.
  for (const tier of tiers.reverse()) { // Try highest rarity first.
    draw -= weights[tier] // Each tier takes its slice of the 0–100 range.
    if (draw < 0) {
      selected = tier
      break
    }
  }
  const candidates = groups[selected]
  // Equal chance for every number WITHIN the chosen tier.
  return candidates[Math.floor(Math.random() * candidates.length)]
}

The lowest tier doesn’t get the same cap. It just receives the leftovers. A tier can also be missing entirely. For example, the 91–100 pack has no legendary numbers because none of those numbers is both prime and a Fibonacci number. The selection function’s fallback sends that missing tier’s “unused probability” to the lowest tier present, which is common in this case.

For ordinary rolls, 6 doesn’t get special treatment compared with the other common numbers. The same adjustment rule changes the starting weights slightly. There are 23 rare numbers in the full pool, so rare gets capped at 23% instead of 25%, and common gets the extra 2%.

TierAdjusted tier chanceChance of each number
Common, 52 numbers62%About 1.192%
Rare, 23 numbers23%1%
Epic, 20 numbers13%0.65%
Legendary, 5 numbers2%0.4%

But when that same rule runs on the smaller pool in a pack, things get interesting. For the 1–10 pack, where my problem was, the math looks like this:

TierNumbers in the packStarting tier chanceAdjusted tier chance
Common660%63%
Rare1, 4, 8, 9, 1025%25%
Epic713%10%
Legendary2, 3, 52%2%

Epic loses 3 percentage points to the cap, and common gets them. Since 6 is the only common, it gets the whole 63%, before the pack bonus7. Here’s how that plays out:

The epic tier is capped from 13% to 10%, sending 3 percentage points to common. Its only number, 6, gets 63%, while each legendary gets about 0.67%, before the pack bonus.

So when I was opening these packs looking for 3, each initial pick was roughly 94 times as likely to give me 6 instead, before the bonus. Maybe I should be writing a strongly worded letter to the developer instead :)

Interestingly, the same code that makes the 1–10 pack this heavily biased towards 6 makes the 91–100 pack evenly balanced. There are no legendaries, so that “unused probability” goes to the lowest tier present.

TierNumbers in the packStarting tier chanceAdjusted tier chance
Common91, 92, 93, 94, 95, 96, 98, 9960%80%
Rare10025%10%
Epic9713%10%
LegendaryNone2%0%

Common gets the spare 15 percentage points from rare, 3 from epic, and the missing legendary tier’s 2% through the fallback. That’s 80%, split between eight numbers, so each gets 10%. The rare and epic numbers also get 10% each.

I generated a graph so I could put these two side by side. Also, graphs are cool :)

Per-slot odds in the 1–10 and 91–100 packs, before pack bonuses

Same function, different mix of numbers. In one pack the extra chance has eight places to go, and in the other it all goes to 6.

Now let’s account for the bonus. For packs rated rare or higher, if the initial numbers don’t include any from the best tier available in that pack, there is a 75% chance that one random slot gets replaced with a number from that tier. In the 1–10 pack, if none of the five numbers is a 2, 3 or 5, the bonus can replace one slot with one of those three legendaries. Copycat packs8 skip this bonus, even when copying the same pack.

With that included, the analysis estimated about 2.71 sixes per regular five-number Aughts pack9, or roughly 54% of its contents. A particular legendary, like 3, averages about 0.26 copies per pack. The expected result was still roughly ten sixes for every three. So the bonus helps you get a legendary, but more than half the numbers would still be sixes on average.

Was this actually happening in my save?

While going back and forth, I was thinking of getting my saved data out because I thought that if it let me work out which number hit level 9 first, I might be able to see a pattern there as well. Reading the code is one thing, but I also wanted to check what I had actually collected. Initially, I thought it would be difficult since I played on my phone and couldn’t just use “inspect page”, but it turned out to be pretty simple.

I just added a bookmark with the following URL in my browser and then opened that bookmark while on the game page:

javascript
javascript:void((s=>s?((a)=>(a.href=URL.createObjectURL(new Blob([s],{type:'text/plain'})),a.download='number-gacha-save.txt',document.body.appendChild(a),a.click(),a.remove()))(document.createElement('a')):alert('No save found'))(localStorage.getItem('gacha')))

That exported the base64 stored in localStorage into a text file for me. Then I just decoded it to get valid JSON containing all 51 fields that the game’s save function writes.

The save had a numbers object with the totals and a rolls array containing 8,728 history entries, newest first. The history length also matched the number shown on the completion screen. And lo and behold, 6 had 191 copies. The next highest was 54, with 132. So yes, I had a lot of sixes. It wasn’t just an “age catching up with me” thing. I really had collected way more sixes than any other number.

Total copies of each number in my save, coloured by rarity

As you can see in the graph, 6 is just standing tall. But the save doesn’t tell us whether each copy came from a normal roll, a pack or an event10. So we know I collected 191 sixes, but we can’t say exactly how many came from 1–10 packs.

The agent did try to figure this out based on the order of the numbers in the saved data, but it wasn’t reliable enough. Its reasoning was that most packs give five numbers together, so five adjacent entries all between 1 and 10 could be an Aughts pack. In the saved data, it found 36 possible packs like that, containing 103 sixes out of 180 numbers, or about 57%. That’s close to the roughly 54% expected after the bonus, but those are possible packs, not confirmed ones. Ordinary rolls can also produce matching groups, and a group can cross pack boundaries.

But as I said, this was a guesstimate from the agent, and it identified more supposed packs than I had actually opened11. So I decided not to put too much weight on this estimated breakdown.

My broader theory about multiples-of-6 didn’t really hold up. Some of those numbers were high, but so were 32 and 64, which aren’t multiples of 6. Different numbers also appear in different packs, so their final totals depend on what I bought, not just on their normal-roll odds.

One last thing, though: I wonder if the dev wanted the Aughts pack to behave that way, or if it was something they just accepted after deciding the numbers’ rarity tiers.

Anyways, I was somewhat right, and I was happy that the extra sixes weren’t just my imagination. I kept buying a pack where the only common number gets most of the probability, then getting annoyed when it gave me the common number. It might have been quicker to start with my saved data, but well, where’s the fun in that?

Still don’t like 59, though.


  1. I guess that is the point of gacha games? ↩︎

  2. Actually, now that I think about it, I would have loved that. ↩︎

  3. Just like the whole world we are in. ↩︎

  4. Most primes, for example. ↩︎

  5. Already feeling biased. ↩︎

  6. Yes, even though all I did was write prompts, I’d like to pretend I did it. ↩︎

  7. Some packs can replace one result with a higher-rarity number. These odds are before that bonus. ↩︎

  8. A Copycat pack copies the last pack type you opened, but skips its bonus. ↩︎

  9. The game’s name for the 1–10 pack. ↩︎

  10. A temporary event boosts a particular number’s chance when you use the event’s own roll button. ↩︎

  11. The save records the exact total in numPacksOpened: 764 for me. ↩︎