Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development

Follow publication

Member-only story

Can you really win at Gambling? A Real Casino vs Computer Simulation

Dmitrii Eliuseev
Dev Genius
Published in
15 min readFeb 13, 2022

--

When I once again turned on Spotify and saw an advertisement “Play Our Fancy Lotto And Win a Million”, it became really annoying. Is it really possible to earn money from gambling? Luckily, you don’t have to spend real money to know the answer. I will show how to make an easy computer simulation without installing any software tools. I also compared my simulation with a real game in the casino — you don’t have to spend your money to see the results, for the sake of science I already did it.

The code below is pretty simple and intended for beginners, those who are not interested in programming at all can just skip the first two chapters.

JupyterLab

To simulate the gambling process, I will create a ‘virtual’ player, will give ‘him’ (or ‘her’ if you prefer) a virtual 100$, and will see how much this player can win. I will use Python JupyterLab for the simulation, it’s a nice free tool to write code and immediately see the results. JupyterLab can run locally, which is faster and more stable, but if you don’t want to install any tools, online IDE can also be used. I am not placing here the links, just because they are often changing and become outdated very fast. Just search “jupyterlab online” and select any link you want. You will see something like this:

Select “Python 3 Notebook"; the IDE will be opened. Copy this code to the first cell:

import random
import numpy as np

%matplotlib inline
import matplotlib.pyplot as plt

plt.rcParams['figure.figsize'] = [14, 5]

def running_mean(x, N):
cumsum = np.cumsum(np.insert(x, 0, 0))
return (cumsum[N:] - cumsum[:-N]) / float(N)

The code is importing a Random library, which we will use to simulate different bets, and the Matplotlib library, which we will use for drawing the graphics. I’ve also imported a NumPy scientific-grade library, which will help us draw average values. Now, if you press the “Play” button, the cursor should go to the next cell:

If you see no errors then it works, and we are ready for coding. If you want to use the…

--

--

Published in Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development

Written by Dmitrii Eliuseev

Python/IoT developer and data engineer, data science and electronics enthusiast

Responses (2)

Write a response