Simulating Roulette Betting Strategies with Python

Minding The Data
6 min readAug 30, 2020

In this article, we’re going to be looking at the popular casino game of roulette and debunking various betting strategies designed to increase your odds of walking away a profitable gambler. We will go over how to simulate each of these methods in Python, while also pointing out the key differences between their effects on your bankroll over time.

So let’s dive in! In American Roulette, there are 18 red pockets, 18 black pockets, and 2 green pockets that the ball can fall into after spinning around the wheel.

If you win on a red or black bet, you get paid 1:1 odds, which means you win $1 for every $1 that you bet. However, if you bet on a single number, the payout improves to 35:1, so you will profit $35 for every $1 bet since there is a much lower chance of winning in this case. In this project, we are going to learn how to simulate random processes such as roulette spins and view the results of simple betting strategies on our bankroll.

Strategy #1: Always Red

Let’s keep this first strategy simple and say that we are going to bet $1 on red every time. Because 18 out of the 38 pockets are red, we have a 18/38 chance of winning $1, and a 20/38 chance that we lose our $1 bet.

Let’s look at how we can simulate this strategy in Python:

We are going to set our bankroll at $100, and then create a list of possible outcomes by making a list with 18 reds, 18 blacks, and 2 greens. Next we are going to use the random library to pick a random item from this list simulating a roulette spin, and if it is red we win $1, but if it is black or green we lose $1. As we go along we will keep track of our bankroll after each spin until we eventually hit $0.

import random

def always_red(bankroll):
bankroll = 100
pockets = ["Red"] * 18 + ["Black"] * 18 + ["Green"] * 2
bankroll_history = []
while bankroll > 0:
roll = random.choice(pockets)
if roll == "Red":
bankroll += 1
else:
bankroll -= 1
bankroll_history.append(bankroll)
return bankroll_history

Now let’s simulate this strategy a few times and make a plot of our bankrolls over time.

import seaborn as sns
import matplotlib.pyplot as plt
sns.set(rc={'figure.figsize':(11.7,8.27)})
for i in range(4):
plt.plot(always_red(bankroll=100), linewidth=2)

plt.xlabel("Number of Games", fontsize=18, fontweight="bold")
plt.ylabel("Bankroll", fontsize=18, fontweight="bold")
plt.xticks(fontsize=16, fontweight="bold")
plt.yticks(fontsize=16, fontweight="bold")
plt.title("Bankroll Over Time", fontsize=22, fontweight="bold")

We can see that each of our 4 simulations goes bankrupt after enough time, but the quickest lasted around 1,000 games while slowest lasted nearly 4,000 games.

Strategy #2: Martingale

Now let’s look at a more complex strategy known as the Martingale. In this strategy, we will start with betting only $0.01, but each time we lose, we will continue to double our bet until we eventually get a win. For example, if we lose the first $0.01 bet, we will bet $0.02 on the next bet trying to make up for the previous loss. If we lose that bet, we will then bet $0.04 and so on until we finally get a win and reset to our initial bet of $0.01.

In the code below, we can see that we are resetting the bet to $0.01 if we win, and multiplying the bet by 2 if we lose. If our bet is ever larger than our bankroll, we set the bet to be equal to our bankroll so that we are not betting more than we have.

def martingale(bankroll):
bet = .01
pockets = ["Red"] * 18 + ["Black"] * 18 + ["Green"] * 2
bankroll_history = []
while bankroll > 0:
if bet > bankroll:
bet = bankroll
roll = random.choice(pockets)
if roll == "Red":
bankroll += bet
bet = .01
else:
bankroll -= bet
bet *=2
bankroll_history.append(bankroll)
return bankroll_history

martingale(bankroll=100)

Let’s simulate this strategy a few times and see how it turns out.

for i in range(4):
plt.plot(martingale(bankroll=100), linewidth=2)

plt.xlabel("Number of Games", fontsize=18, fontweight="bold")
plt.ylabel("Bankroll", fontsize=18, fontweight="bold")
plt.xticks(fontsize=16, fontweight="bold")
plt.yticks(fontsize=16, fontweight="bold")
plt.title("Bankroll Over Time", fontsize=22, fontweight="bold")

We can already see that this looks much different than our “Always Red” strategy. With the Martingale strategy, you make slow and steady profits, until you hit a string of losses which eventually causes you to go bankrupt because your bets are increasing exponentially. From the graph above, we can see that one simulation made it all the way to 30,000 games, while another only lasted a few hundred rounds.

Strategy #3: Fibonacci

The Fibonacci sequence is the sequence of numbers defined by:

X1 = 1, X2 = 1, and Xn = Xn-1 + Xn-2

Which means the first 10 Fibonacci numbers are 1, 1, 2, 3, 5, 8, 13, 21, 34, 55.

In the Fibonacci strategy, we are going to start by betting $0.01, and then if we lose we will move 1 step up the chain of Fibonacci numbers. However if we win, we will move 2 steps down the sequence (or continue betting 1 if we are already there). For example, let’s say we lose the first 5 bets of $0.01, $0.01, $0.02, $0.03, and $0.05, but we win the bet of $0.08. We would then move two steps down the chain and bet $0.03.

Let’s look at how we would code this in Python:

First we define a function which gets us the nth Fibonacci number. Then we multiply whichever Fibonacci number we’re at by $0.01 to get our bet. If we win our bet, we decrease our Fibonacci number by 2, but make sure not to decrease it less than 1. If we lose the bet then we increase the Fibonacci number by 1.

def fibonacci(n):
if n == 1 or n == 2:
return 1
else:
return fibonacci(n-1) + fibonacci(n-2)
def fibonacci_strategy(bankroll):
fibonacci_number = 1
pockets = ["Red"] * 18 + ["Black"] * 18 + ["Green"] * 2
bankroll_history = []
while bankroll > 0:
bet = fibonacci(fibonacci_number) * .01
if bet > bankroll:
bet = bankroll
roll = random.choice(pockets)
if roll == "Red":
bankroll += bet
fibonacci_number = max(fibonacci_number - 2, 1)
else:
bankroll -= bet
fibonacci_number += 1
bankroll_history.append(bankroll)
return bankroll_history

Let’s see how these simulations turned out.

for i in range(4):
plt.plot(fibonacci_strategy(bankroll=100), linewidth=2)

plt.xlabel("Number of Games", fontsize=18, fontweight="bold")
plt.ylabel("Bankroll", fontsize=18, fontweight="bold")
plt.xticks(fontsize=16, fontweight="bold")
plt.yticks(fontsize=16, fontweight="bold")
plt.title("Bankroll Over Time", fontsize=22, fontweight="bold")

These simulations look very similar to the Martingale strategy, but it does look like they last longer since they are increasing their bet at a slower rate. After simulating both 100 times, the Martingale strategy lasted an average of 17,800 rounds, while the Fibonacci strategy lasted an average of 21,200 rounds.

Conclusion

We’ve tested multiple strategies and have seen that it is not going to be possible to beat roulette in the long term, but it is possible to extend the time that you’re able to play.

Hopefully you are now able to test any other strategies that you are interested in, and feel free to contact me on the Contact page for any questions / comments!

--

--