The short answer: the math SDK is Stake Engine's free, open-source Python framework for the math of a slot. You describe the game in Python, the SDK plays it many thousands of times, an optimizer sets how likely each round is so the game hits its RTP, and it writes the three files Engine needs: index.json, a lookup table (CSV) and the books (compressed JSON lines).
This is a beginner's tour of the SDK (Engine was called Stake Engine until September 2026; the SDK still uses the old name). We use it for every game we ship, so the file names and code below are the real ones from the SDK's repository. New to Engine itself? Read our beginner's guide to Engine first.

Why Engine wants every round in advance
A classic slot server spins the reels live and computes the result on the spot. Engine works differently: every possible outcome your game can give is decided before the game is published. The SDK simulates a large set of rounds and saves each one as a "book" (the list of events: the board, the wins, the bonus). Next to the books, a lookup table gives every round its probability and its payout.
When a player spins, Engine picks one round from the lookup table by its probability and sends that book to the game, which plays it on screen. Because every round and its probability are known, Engine can compute the game's exact RTP and win distribution at upload time.

What you need
- Python 3.12 or newer, with pip.
- Rust and Cargo, if you use the included optimizer (you will).
- Make, for the one-line setup.
- A computer or a cloud development environment. We run ours in the cloud and drive it from a phone.
The SDK's own documentation is at engineio.github.io/math-sdk.
Step 1: set it up and run a sample game
From the SDK's folder, one command creates a Python environment and installs everything; a second one runs a sample game:
make setup
make run GAME=0_0_linesThe SDK comes with sample games to learn from: 0_0_lines (paylines), 0_0_ways (ways to win), 0_0_cluster (cluster pays), 0_0_scatter (pay anywhere) and 0_0_expwilds (expanding wilds). Start with the one closest to the game you want to make, copy its folder, and change it.
Step 2: what's inside a game folder

Two files hold most of a game: game_config.py (what the game is) and gamestate.py (how a round plays). The others add your game's own actions and calculations, set the optimizer's targets, and run everything.
Step 3: describe the game in game_config.py
The config holds the board, the paytable, the special symbols, the reels and the game's RTP and max win. A shortened version of the lines sample:
self.game_id = "0_0_lines"
self.wincap = 5000.0 # max win, in multiples of the bet
self.win_type = "lines"
self.rtp = 0.9670
self.num_reels = 5
self.num_rows = [3] * self.num_reels
self.paytable = {
(5, "H1"): 50, (4, "H1"): 20, (3, "H1"): 10,
(5, "L1"): 5, (4, "L1"): 1, (3, "L1"): 0.5,
# ...
}
self.special_symbols = {"wild": ["W"], "scatter": ["S"], "multiplier": ["W"]}
self.freespin_triggers = {
self.basegame_type: {3: 8, 4: 12, 5: 15}, # 3 scatters = 8 free spins
}The reel strips live in the reels/ folder as CSV files, one column per reel.
Step 4: bet modes and distributions
Each bet mode (the base game, a bonus buy, an ante) is a BetMode with its cost, RTP and max win. Inside it, distributions tell the SDK what kinds of rounds to simulate and how many of each:
BetMode(
name="base",
cost=1.0,
rtp=self.rtp,
max_win=5000,
distributions=[
Distribution(criteria="wincap", quota=0.001, win_criteria=5000, conditions=wincap_condition),
Distribution(criteria="freegame", quota=0.1, conditions=freegame_condition),
Distribution(criteria="0", quota=0.4, win_criteria=0.0, conditions=zerowin_condition),
Distribution(criteria="basegame", quota=0.5, conditions=basegame_condition),
],
)The quotas are the share of simulated rounds of each kind, not how often players will see them. That's the optimizer's job: it later sets the real probability of every round. Forcing some max-win rounds (wincap) is what guarantees your top prize exists in the books.
Step 5: write how a round plays in gamestate.py
The round logic reads almost like the rules of the game. From the lines sample:
def run_spin(self, sim, simulation_seed=None):
self.reset_seed(sim)
self.repeat = True
while self.repeat:
self.reset_book()
self.draw_board()
self.evaluate_lines_board() # find and pay the wins
self.win_manager.update_gametype_wins(self.gametype)
if self.check_fs_condition():
self.run_freespin_from_base() # enough scatters: free spins
self.evaluate_finalwin()
self.check_repeat() # redo if the round doesn't fit its distribution
self.imprint_wins()Every step writes events into the book, and those events are exactly what the front end will animate. Design them together with the front end: a game can only show what the book tells it.
Step 6: run it and get the files
run.py sets how many rounds to simulate per mode and which stages to run:
num_sim_args = {"base": int(1e4), "bonus": int(1e4)}
run_conditions = {
"run_sims": True, # play the game and write the books
"run_optimization": True, # set each round's probability (Rust)
"run_analysis": True, # stats: RTP, hit rate, win distribution
"run_format_checks": True, # check the files the way Engine will
}The samples use 10,000 rounds per mode to run fast; a real game uses far more. The result lands in library/publish_files/: one index.json that lists your modes, and for each mode a lookup table and a books file.
{
"modes": [
{"name": "base", "cost": 1.0, "events": "books_base.jsonl.zst", "weights": "lookUpTable_base_0.csv"},
{"name": "bonus", "cost": 100.0, "events": "books_bonus.jsonl.zst", "weights": "lookUpTable_bonus_0.csv"}
]
}Each line of a lookup table is round id, probability weight, payout multiplier (for example 2,25668581149,20), and every book has at least an id, its events and its payoutMultiplier. That folder is what you upload to Engine.
Six mistakes beginners make
- Too few simulations. Rare wins need enough rounds, or the win distribution is noisy and the optimizer has little to work with.
- Payouts that don't match. The payout in each lookup table row must match the payout in its book exactly; Engine checks it.
- A max win that never happens. If no book reaches the advertised max win, the rules lie. Force wincap rounds.
- Checking only the base game. Every mode, including bonus buys, needs its own RTP and max-win check.
- Events the front end can't play. Agree on the events before writing the round logic.
- Looking only at RTP. Engine's review also looks at how wins are spread (how often big wins come). Read how Stake Engine reviews a slot.
Where AI helps
An AI assistant like Claude is very good at this kind of code: give it the rules of your game in plain English and the sample closest to it, and it writes the config, the round logic and the tests with you. You still need to understand what it writes and check the numbers. Our Own Your Slot Guide has the prompts we use for every step, from the math to the front end.
Choose your way in
- Build it yourself: The Own Your Slot Guide. The whole process with Claude, 62 prompts, from the math to approval.
- Math done, game next? LLM2D. AI animation for the front end, no Spine licence.
- Rather skip the math? Custom Slot. Your theme and your math targets, built in 14 days. See what buying or building a slot costs.
Frequently asked questions
What is the Stake Engine math SDK?
It's Stake Engine's open-source Python framework for a slot's math. It simulates the game, optimizes how likely each round is, and writes the index.json, lookup tables and books that Engine needs.
What language does it use?
Python 3.12 or newer for the game, and Rust for the included optimizer.
What files does Engine need for the math?
An index.json that lists the modes, and for every mode a lookup table (CSV of round id, probability and payout) and a books file (zstandard-compressed JSON lines with each round's events).
Is the math SDK free?
Yes. It's open source under the MIT licence.
Do I need to be good at maths?
You need to understand RTP, hit rate and volatility, but the SDK and an AI assistant do the heavy calculation. Start from a sample game and change one thing at a time.
Sources: the Stake Engine math SDK repository and documentation (code shortened from its 0_0_lines sample game, MIT licence). Own Your Slot is an independent studio and is not affiliated with Stake or Engine. 18+. Gamble responsibly.
