FA-86121 / Game economy crafting balance / Open access
Magic find loot roll: Roll wraps modulo total weight · case 01
Drop rates depend on how the table total divides 10000.
ROOT CAUSE
The roll is reduced modulo the total instead of scaled.
VERIFIED REPAIR
Restore `roll * total // 10000` at the roll scaling step.
Unsuccessful approach: Scaling by 9999 makes the top roll overshoot the table.
Case contract
table = [[item, rarity, weight], ...]. Non-common weights become floor(w*(100+mf)/100) (mf may be negative). With total boosted weight T (None if 0), target = floor(roll*T/10000) for roll 0..9999; return the first item whose cumulative boosted weight exceeds target.
Why this case matters
Game economies leak or destroy currency when one crafting or pricing rule is off by one boundary, rounding stage or state update; the defect is observable in exact integer outcomes.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(table, roll, magic_find):
weights = []
for item, rarity, w in table:
if rarity != 'common':
w = w * (100 + magic_find) // 100
weights.append(w)
total = sum(weights)
if total == 0:
return None
target = roll % total
acc = 0
for (item, rarity, w0), w in zip(table, weights):
acc += w
if target < acc:
return item
return None
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('fault site roll scaling #1',
[[['i0', 'common', 10], ['i1', 'common', 50], ['i2', 'legendary', 50]], 793, -50],
'i0'),
('partial repair boundary #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1'),
('regression roll scaling #1',
[[['i0', 'rare', 1],
['i1', 'rare', 39],
['i2', 'legendary', 1],
['i3', 'rare', 50],
['i4', 'legendary', 5]],
9999,
0],
'i4'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1', [[['i0', 'rare', 1], ['i1', 'common', 10], ['i2', 'legendary', 93]], 0, 100], 'i0'),
('control #2',
[[['i0', 'rare', 2], ['i1', 'legendary', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 5]], 0, -50],
'i0')],
[('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('fault site roll scaling #1',
[[['i0', 'common', 10], ['i1', 'common', 50], ['i2', 'legendary', 50]], 793, -50],
'i0'),
('regression roll scaling #1',
[[['i0', 'rare', 1],
['i1', 'rare', 39],
['i2', 'legendary', 1],
['i3', 'rare', 50],
['i4', 'legendary', 5]],
9999,
0],
'i4'),
('partial repair boundary #1',
[[['i0', 'rare', 0], ['i1', 'legendary', 2], ['i2', 'common', 2], ['i3', 'common', 1]], 9999, 0],
'i3'),
('regression roll scaling #2',
[[['i0', 'legendary', 1], ['i1', 'common', 5], ['i2', 'legendary', 0], ['i3', 'legendary', 5]], 9999, 50],
'i3'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1',
[[['i0', 'rare', 2], ['i1', 'legendary', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 5]], 0, -50],
'i0'),
('control #2',
[[['i0', 'legendary', 10],
['i1', 'rare', 50],
['i2', 'legendary', 0],
['i3', 'common', 2],
['i4', 'common', 55]],
0,
-50],
'i0')],
[('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('regression roll scaling #1',
[[['i0', 'legendary', 1], ['i1', 'common', 5], ['i2', 'legendary', 0], ['i3', 'legendary', 5]], 9999, 50],
'i3'),
('regression roll scaling #2',
[[['i0', 'rare', 5],
['i1', 'legendary', 10],
['i2', 'legendary', 2],
['i3', 'rare', 86],
['i4', 'legendary', 1]],
9999,
100],
'i4'),
('partial repair boundary #1',
[[['i0', 'common', 5], ['i1', 'common', 2], ['i2', 'common', 50]], 9999, 50],
'i2'),
('partial repair boundary #2', [[['i0', 'legendary', 50], ['i1', 'rare', 35]], 9999, 100], 'i1'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1', [[['i0', 'rare', 0], ['i1', 'rare', 1]], 494, 100], 'i1'),
('control #2', [[['i0', 'rare', 50], ['i1', 'common', 0]], 1029, -22], 'i0')],
[('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('fault site roll scaling #1',
[[['i0', 'common', 1], ['i1', 'legendary', 0], ['i2', 'rare', 10]], 1, 50],
'i0'),
('fault site roll scaling #2',
[[['i0', 'rare', 10], ['i1', 'rare', 50], ['i2', 'rare', 5], ['i3', 'common', 10]], 5000, -50],
'i1'),
('regression roll scaling #1',
[[['i0', 'rare', 5],
['i1', 'legendary', 10],
['i2', 'legendary', 2],
['i3', 'rare', 86],
['i4', 'legendary', 1]],
9999,
100],
'i4'),
('partial repair boundary #1',
[[['i0', 'common', 5], ['i1', 'rare', 1], ['i2', 'rare', 5]], 9999, 250],
'i2'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1', [[['i0', 'legendary', 0], ['i1', 'common', 5]], 1, 250], 'i1'),
('control #2', [[['i0', 'common', 50]], 1, 100], 'i0')],
[('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('regression roll scaling #1',
[[['i0', 'rare', 2],
['i1', 'legendary', 10],
['i2', 'common', 10],
['i3', 'common', 5],
['i4', 'rare', 10]],
9999,
100],
'i4'),
('fault site roll scaling #1',
[[['i0', 'legendary', 50],
['i1', 'common', 2],
['i2', 'common', 1],
['i3', 'common', 0],
['i4', 'legendary', 50]],
5000,
250],
'i1'),
('partial repair boundary #1', [[['i0', 'rare', 5]], 9999, 100], 'i0'),
('partial repair boundary #2', [[['i0', 'common', 10]], 9999, 130], 'i0'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1', [[['i0', 'common', 50], ['i1', 'legendary', 5], ['i2', 'legendary', 1]], 0, 100], 'i0'),
('control #2', [[['i0', 'common', 2]], 0, 0], 'i0')]]
for label, args, expected in cases[N-1]:
check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| legendary boosted #1 | sword | crown | Failed |
| zero weight entry skipped #1 | a | c | Failed |
| fault site roll scaling #1 | i1 | i0 | Failed |
| partial repair boundary #1 | i1 | i1 | Passed |
| regression roll scaling #1 | i1 | i4 | Failed |
| curse lowers rare #1 | rock | rock | Passed |
| control #1 | i0 | i0 | Passed |
| control #2 | i0 | i0 | Passed |
SHA-256 / 46df3a1feb2e91ce16cecd312c875c23596019c4714ae15aa3c223255077b413
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(table, roll, magic_find):
weights = []
for item, rarity, w in table:
if rarity != 'common':
w = w * (100 + magic_find) // 100
weights.append(w)
total = sum(weights)
if total == 0:
return None
target = roll * total // 9999
acc = 0
for (item, rarity, w0), w in zip(table, weights):
acc += w
if target < acc:
return item
return None
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('fault site roll scaling #1',
[[['i0', 'common', 10], ['i1', 'common', 50], ['i2', 'legendary', 50]], 793, -50],
'i0'),
('partial repair boundary #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1'),
('regression roll scaling #1',
[[['i0', 'rare', 1],
['i1', 'rare', 39],
['i2', 'legendary', 1],
['i3', 'rare', 50],
['i4', 'legendary', 5]],
9999,
0],
'i4'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1', [[['i0', 'rare', 1], ['i1', 'common', 10], ['i2', 'legendary', 93]], 0, 100], 'i0'),
('control #2',
[[['i0', 'rare', 2], ['i1', 'legendary', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 5]], 0, -50],
'i0')],
[('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('fault site roll scaling #1',
[[['i0', 'common', 10], ['i1', 'common', 50], ['i2', 'legendary', 50]], 793, -50],
'i0'),
('regression roll scaling #1',
[[['i0', 'rare', 1],
['i1', 'rare', 39],
['i2', 'legendary', 1],
['i3', 'rare', 50],
['i4', 'legendary', 5]],
9999,
0],
'i4'),
('partial repair boundary #1',
[[['i0', 'rare', 0], ['i1', 'legendary', 2], ['i2', 'common', 2], ['i3', 'common', 1]], 9999, 0],
'i3'),
('regression roll scaling #2',
[[['i0', 'legendary', 1], ['i1', 'common', 5], ['i2', 'legendary', 0], ['i3', 'legendary', 5]], 9999, 50],
'i3'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1',
[[['i0', 'rare', 2], ['i1', 'legendary', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 5]], 0, -50],
'i0'),
('control #2',
[[['i0', 'legendary', 10],
['i1', 'rare', 50],
['i2', 'legendary', 0],
['i3', 'common', 2],
['i4', 'common', 55]],
0,
-50],
'i0')],
[('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('regression roll scaling #1',
[[['i0', 'legendary', 1], ['i1', 'common', 5], ['i2', 'legendary', 0], ['i3', 'legendary', 5]], 9999, 50],
'i3'),
('regression roll scaling #2',
[[['i0', 'rare', 5],
['i1', 'legendary', 10],
['i2', 'legendary', 2],
['i3', 'rare', 86],
['i4', 'legendary', 1]],
9999,
100],
'i4'),
('partial repair boundary #1',
[[['i0', 'common', 5], ['i1', 'common', 2], ['i2', 'common', 50]], 9999, 50],
'i2'),
('partial repair boundary #2', [[['i0', 'legendary', 50], ['i1', 'rare', 35]], 9999, 100], 'i1'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1', [[['i0', 'rare', 0], ['i1', 'rare', 1]], 494, 100], 'i1'),
('control #2', [[['i0', 'rare', 50], ['i1', 'common', 0]], 1029, -22], 'i0')],
[('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('fault site roll scaling #1',
[[['i0', 'common', 1], ['i1', 'legendary', 0], ['i2', 'rare', 10]], 1, 50],
'i0'),
('fault site roll scaling #2',
[[['i0', 'rare', 10], ['i1', 'rare', 50], ['i2', 'rare', 5], ['i3', 'common', 10]], 5000, -50],
'i1'),
('regression roll scaling #1',
[[['i0', 'rare', 5],
['i1', 'legendary', 10],
['i2', 'legendary', 2],
['i3', 'rare', 86],
['i4', 'legendary', 1]],
9999,
100],
'i4'),
('partial repair boundary #1',
[[['i0', 'common', 5], ['i1', 'rare', 1], ['i2', 'rare', 5]], 9999, 250],
'i2'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1', [[['i0', 'legendary', 0], ['i1', 'common', 5]], 1, 250], 'i1'),
('control #2', [[['i0', 'common', 50]], 1, 100], 'i0')],
[('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('regression roll scaling #1',
[[['i0', 'rare', 2],
['i1', 'legendary', 10],
['i2', 'common', 10],
['i3', 'common', 5],
['i4', 'rare', 10]],
9999,
100],
'i4'),
('fault site roll scaling #1',
[[['i0', 'legendary', 50],
['i1', 'common', 2],
['i2', 'common', 1],
['i3', 'common', 0],
['i4', 'legendary', 50]],
5000,
250],
'i1'),
('partial repair boundary #1', [[['i0', 'rare', 5]], 9999, 100], 'i0'),
('partial repair boundary #2', [[['i0', 'common', 10]], 9999, 130], 'i0'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1', [[['i0', 'common', 50], ['i1', 'legendary', 5], ['i2', 'legendary', 1]], 0, 100], 'i0'),
('control #2', [[['i0', 'common', 2]], 0, 0], 'i0')]]
for label, args, expected in cases[N-1]:
check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| legendary boosted #1 | crown | crown | Passed |
| zero weight entry skipped #1 | c | c | Passed |
| fault site roll scaling #1 | i0 | i0 | Passed |
| partial repair boundary #1 | None | i1 | Failed |
| regression roll scaling #1 | None | i4 | Failed |
| curse lowers rare #1 | rock | rock | Passed |
| control #1 | i0 | i0 | Passed |
| control #2 | i0 | i0 | Passed |
SHA-256 / 6619c49eb4c2d82a95117c747509a3aa11f9d46220f1bfa34a38fc568c0f3670
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(table, roll, magic_find):
weights = []
for item, rarity, w in table:
if rarity != 'common':
w = w * (100 + magic_find) // 100
weights.append(w)
total = sum(weights)
if total == 0:
return None
target = roll * total // 10000
acc = 0
for (item, rarity, w0), w in zip(table, weights):
acc += w
if target < acc:
return item
return None
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('fault site roll scaling #1',
[[['i0', 'common', 10], ['i1', 'common', 50], ['i2', 'legendary', 50]], 793, -50],
'i0'),
('partial repair boundary #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1'),
('regression roll scaling #1',
[[['i0', 'rare', 1],
['i1', 'rare', 39],
['i2', 'legendary', 1],
['i3', 'rare', 50],
['i4', 'legendary', 5]],
9999,
0],
'i4'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1', [[['i0', 'rare', 1], ['i1', 'common', 10], ['i2', 'legendary', 93]], 0, 100], 'i0'),
('control #2',
[[['i0', 'rare', 2], ['i1', 'legendary', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 5]], 0, -50],
'i0')],
[('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('fault site roll scaling #1',
[[['i0', 'common', 10], ['i1', 'common', 50], ['i2', 'legendary', 50]], 793, -50],
'i0'),
('regression roll scaling #1',
[[['i0', 'rare', 1],
['i1', 'rare', 39],
['i2', 'legendary', 1],
['i3', 'rare', 50],
['i4', 'legendary', 5]],
9999,
0],
'i4'),
('partial repair boundary #1',
[[['i0', 'rare', 0], ['i1', 'legendary', 2], ['i2', 'common', 2], ['i3', 'common', 1]], 9999, 0],
'i3'),
('regression roll scaling #2',
[[['i0', 'legendary', 1], ['i1', 'common', 5], ['i2', 'legendary', 0], ['i3', 'legendary', 5]], 9999, 50],
'i3'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1',
[[['i0', 'rare', 2], ['i1', 'legendary', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 5]], 0, -50],
'i0'),
('control #2',
[[['i0', 'legendary', 10],
['i1', 'rare', 50],
['i2', 'legendary', 0],
['i3', 'common', 2],
['i4', 'common', 55]],
0,
-50],
'i0')],
[('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('regression roll scaling #1',
[[['i0', 'legendary', 1], ['i1', 'common', 5], ['i2', 'legendary', 0], ['i3', 'legendary', 5]], 9999, 50],
'i3'),
('regression roll scaling #2',
[[['i0', 'rare', 5],
['i1', 'legendary', 10],
['i2', 'legendary', 2],
['i3', 'rare', 86],
['i4', 'legendary', 1]],
9999,
100],
'i4'),
('partial repair boundary #1',
[[['i0', 'common', 5], ['i1', 'common', 2], ['i2', 'common', 50]], 9999, 50],
'i2'),
('partial repair boundary #2', [[['i0', 'legendary', 50], ['i1', 'rare', 35]], 9999, 100], 'i1'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1', [[['i0', 'rare', 0], ['i1', 'rare', 1]], 494, 100], 'i1'),
('control #2', [[['i0', 'rare', 50], ['i1', 'common', 0]], 1029, -22], 'i0')],
[('zero weight entry skipped #1',
[[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
'c'),
('fault site roll scaling #1',
[[['i0', 'common', 1], ['i1', 'legendary', 0], ['i2', 'rare', 10]], 1, 50],
'i0'),
('fault site roll scaling #2',
[[['i0', 'rare', 10], ['i1', 'rare', 50], ['i2', 'rare', 5], ['i3', 'common', 10]], 5000, -50],
'i1'),
('regression roll scaling #1',
[[['i0', 'rare', 5],
['i1', 'legendary', 10],
['i2', 'legendary', 2],
['i3', 'rare', 86],
['i4', 'legendary', 1]],
9999,
100],
'i4'),
('partial repair boundary #1',
[[['i0', 'common', 5], ['i1', 'rare', 1], ['i2', 'rare', 5]], 9999, 250],
'i2'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1', [[['i0', 'legendary', 0], ['i1', 'common', 5]], 1, 250], 'i1'),
('control #2', [[['i0', 'common', 50]], 1, 100], 'i0')],
[('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
('regression roll scaling #1',
[[['i0', 'rare', 2],
['i1', 'legendary', 10],
['i2', 'common', 10],
['i3', 'common', 5],
['i4', 'rare', 10]],
9999,
100],
'i4'),
('fault site roll scaling #1',
[[['i0', 'legendary', 50],
['i1', 'common', 2],
['i2', 'common', 1],
['i3', 'common', 0],
['i4', 'legendary', 50]],
5000,
250],
'i1'),
('partial repair boundary #1', [[['i0', 'rare', 5]], 9999, 100], 'i0'),
('partial repair boundary #2', [[['i0', 'common', 10]], 9999, 130], 'i0'),
('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
('control #1', [[['i0', 'common', 50], ['i1', 'legendary', 5], ['i2', 'legendary', 1]], 0, 100], 'i0'),
('control #2', [[['i0', 'common', 2]], 0, 0], 'i0')]]
for label, args, expected in cases[N-1]:
check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| legendary boosted #1 | crown | crown | Passed |
| zero weight entry skipped #1 | c | c | Passed |
| fault site roll scaling #1 | i0 | i0 | Passed |
| partial repair boundary #1 | i1 | i1 | Passed |
| regression roll scaling #1 | i4 | i4 | Passed |
| curse lowers rare #1 | rock | rock | Passed |
| control #1 | i0 | i0 | Passed |
| control #2 | i0 | i0 | Passed |
SHA-256 / 72029b6130d1a2d7624e65d5b7496a278a2bf047defe597073333a873f6e5cae
Verification & scope
Deterministic toy contract stipulated for this model; integer or exact arithmetic only, not a reproduction of any specific game engine. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:50:46.721385+00:00.
Case digest / 7ffe2be56142e5e400bcc9656d872e9b172f43ed8fa3ddee7b023d9d34052d9d