DEV Community

Daffa Haj Tsaqif
Daffa Haj Tsaqif

Posted on

Try to Prove “The House Always Wins” in Gambling with Python

Hello, I like money

Photo by [Stephen Leonardi](https://unsplash.com/@stephenleo1982?utm_source=medium&utm_medium=referral) on [Unsplash](https://unsplash.com?utm_source=medium&utm_medium=referral)

NOTE: This blog was written in December 2022 in Medium but I republished it to Dev.to as i planned to migrate for my future writing

Editorial Note from the original post:

from the simulation itself, the loss is usually more than the win but I have a bad way to count how much they win and how much they lose and I need to repair this in the future.

but the logic behind the game itself is more or less correct, if anyone saw the flaws please tell me in the repo.

Backstory

So a few days ago my mom talk to me about how one of the neighbors borrowed money for ‘allegedly’ gambling online slots, and I naturally thought “How in the hell do people borrow money to lose it”, and since I always learned since I was little how bad gambling for ourselves, but in another side, I was fascinated in its economy and also the math of probability, heck it’s maybe one of my favorite branch of math(even though I don't really like math).

Simulating Gambling in Python

There are tons and tons of forms of gambling out there, some of them are “Skill-based” like poker, blackjack, and most card-based games out there, and the others are pure chance like slots, roulette, and pachinko(mechanical gambling in japan).

I want to simulate Roulette, more specifically European roulette where it has only one zero compared to the American counterparts where it has 0 and 00. This way the house edge (a mathematical advantage that the house has compared to the player) is lower than if we use American style Roulette to see how much the house will earn from such a small house edge, also its easier to code hehe

Photo by [Derek Lynn](https://unsplash.com/@derek_lynn?utm_source=medium&utm_medium=referral) on [Unsplash](https://unsplash.com?utm_source=medium&utm_medium=referral)

What’s Roulette tho??

According to its Wikipedia page, Roulette is a casino game named after the French word meaning little wheel which was likely developed from the Italian game Biribi. In the game, a player may choose to place a bet on a single number, various groupings of numbers, the color red or black, whether the number is odd or even, or if the numbers are high (19–36) or low (1–18). The odds and the payout will depend on the bet the player placed, the broader the bets the better the odds they'll earn but the lesser the payout.

and how to calculate how much house edge of a game?

Since it's European Roulette, let's say the player places a bet on a single number then there is a 36 in 37 chance that the bet will lose and a 1 in 37 chance that you will earn 35 times your bet, so the house edge will be like below.

−1 × (36⁄37) + 35 × (1⁄37) = −0.0270 or 2.7% in favour of the house.

If it's American or heck, there is roulette with triple zeros, the house edge will naturally be higher so, in general, will have a bigger profit compared to the European one.

That's a general idea of Roulette, I will use Python to simulate how roulette works, and see how much they'll earn(or lose) and also how much the house will make.

The Simulator……Yab-

Shirakami Fubuki Hololive GIF - Shirakami Fubuki Hololive Yabe - Discover & Share GIFs

Click to view the GIF

  <div class="color-secondary fs-s flex items-center">
      <img
        alt="favicon"
        class="c-embed__favicon m-0 mr-2 radius-0"
        src="https://tenor.com/assets/img/favicon/favicon-16x16.png"
        loading="lazy" />
    tenor.com
  </div>
</div>
Enter fullscreen mode Exit fullscreen mode



Obviously, this is the hard part, so….fasten your seatbelt.

OMG, I didn't this blog actually takes a long time to make, too many effort for mere blog post lmao
GitHub - dhupee/roulette-simulation: a simple cli for roullete simulation

so I create this simple CLI to simulate roulette with Monte-Carlo simulation in it, can't really show the code here since its a bit long for this post but you can see it in Github(also give it some improvement hehe).

The CLI of the app, hope it looks self-explanatory

To be honest, I was having fun with this CLI not only I actually learned about Command-Line Interface and JIT compilation I found it interesting.

The Result

running it 3 times with three different tendency settings which just the setting on which bet type the simulator will choose, starter money of 10k, 100 rounds, bet size of 100, and 10000 sessions of betting I got this chart

wait, I don't know if I can place the picture like this

The safe tendency which chooses either dozen, column, odd or even, or other safe bet has such a chart that spread kinda evenly, don't you think??

The others, random and dangerous look kinda towards loss if I see it, the one where the player got profit is kinda sparse.

Do I Prove Anything?

not sure, this simulation has a lot of things left like the distribution chart and other features.

If I eyeball it, looks like it. More so on the random one, the chart looks so dense on the player losing that the chart where it wins it.

let me know more in the comment, and have fun with the script if you want. Better yet, help me improve it.

cheers

Top comments (7)

Collapse
 
s0bacc profile image
S0bacc

I'm not that good at Python rn to do it but the article is quite interesting
Thanks for sharing c:

Collapse
 
tomasgreen profile image
Tommy Cooke • Edited

Diving into the analytics of gambling with Python to prove "the house always wins" is super intriguing! It's a fantastic application of programming skills to explore real-world scenarios and debunk or confirm long-standing theories. The insights from the simulation, despite the noted counting issue, contribute valuable perspectives to the understanding of gambling dynamics. On a related note, for those interested in exploring the world of gambling further, especially from a legal and structured standpoint, checking out legal casinos can offer both an educational and entertaining experience. For those interested in the gambling scene, https://pl.kasynopolska10.com/legalne-kasyna/ is a great resource for finding legal and regulated casinos. It’s always fascinating to see how different countries regulate gambling and the impact of those regulations on both the house and the player.

Collapse
 
serk_kripki_278a72fd5b4d8 profile image
Serk Kripki • Edited

I have been playing on the casino site for a long time. I found this casino in the ranking and I do not regret it. There were no problems at all times and there are plenty of games on the site. Now it offers great bonuses to its new members. If you are curious about which ones, go to 50-spins.com/klarna-online-casinos/ and read the article.

Collapse
 
vikolaz profile image
Rala Volo • Edited

As for me, the most important thing is not what engine is this or that casino is on, but what bonuses and services it offers for the player. For example, I learned that now it is possible in several casinos to get a special VIP program and there are regularly given a variety of bonuses for those who play for larger amounts. And the main thing is that here bstcasinos.com/vip-casinos/ there is a whole list of such casinos where there is this VIP program. I think that many avid players with experience it will be useful.

Collapse
 
wilson124607 profile image
ew2323219

I've always dreamed of visiting a real, land-based casino to feel the real vibe of excitement. Now there is no need for this, since I can get all this without leaving home. And online casinos are also more profitable because there are resources like casinosanalyzer.co.nz/casino-bonus..., where you can find various promocodes and bonus offers. It is unlikely that at least one casino in Vegas offers players bonuses and various promotions.

Collapse
 
archedbishop profile image
Archedbishop

This theory is, actually, very easy to prove. Just find a big numbers formula in the probability theory and play with numbers. I have always known that and never undertaken any big risks. For instance, with Bdg win app it is easier to have fun and earn some cash than you can even imagine. And my invite code opens doors for you. 

Collapse
 
annafrost2390 profile image
AnnaFrost • Edited

Cool! Thanks! Just read this cool article on how to prove that the casino always wins in gambling using Python - really fascinating stuff! By the way, I came across a review of Teen Patti Royal - teen-patti.expert/teen-patti-royal... and it got me thinking about implementing some of these concepts into card games. Is anyone else experimenting with Python in the gambling space? This is really very interesting.