-
-
Save tanghaibao/503788 to your computer and use it in GitHub Desktop.
""" | |
This script simulates a common casino strategy when playing roulette: | |
bet on odd/even, and stick to your choice. bet $20 at start, if you lose, | |
double the bet; if you win, start with the $20 bet again. | |
This simulation suggests that if you follow this strategy for a few rounds (say 50), | |
more than 90% of the people will make money, with only a slight chance of bankrupt | |
$ python casino_strategy.py | |
Simulating 50 rolls per trial and generate 10000 trials | |
mean: 10006, median: 10480 | |
93% of the samples earned money | |
3% of the samples got bankrupt | |
However if you adopt this strategy long enough, eventually you'll lose money. | |
See "gambler's ruin" <http://en.wikipedia.org/wiki/Gambler's_ruin> | |
""" | |
from random import choice | |
import sys | |
w = lambda x: sys.stderr.write("%s\n" % x) | |
class Gambler: | |
__slots__ = ("money",) | |
def __init__(self, money=10000): | |
self.money = money | |
reset = __init__ | |
def roll(self, times=50, verbose=False): | |
bet = 20 | |
for i in range(times): | |
self.money -= bet | |
won = choice((True, False)) # binary choice | |
# the gambling strategy | |
if won: | |
self.money += bet * 2 | |
next_bet = 20 | |
else: | |
next_bet = bet * 2 | |
if verbose: | |
w("bet: %d, %s, balance: %d" % \ | |
(bet, "won" if won else "lost", self.money)) | |
# can't bet more than you have | |
if next_bet > self.money: | |
next_bet = self.money | |
bet = next_bet | |
return self.money | |
if __name__ == "__main__": | |
ITERATIONS = 10000 | |
ROLLS = 50 | |
finals = [] | |
g = Gambler() | |
for i in range(ITERATIONS): | |
g.reset() | |
finals.append(g.roll(times=ROLLS)) | |
import matplotlib.pyplot as plt | |
import numpy as np | |
finals = np.array(finals, dtype=int) | |
w("Simulating %d rolls per trial and generate %d trials" % (ROLLS, ITERATIONS)) | |
w("mean: %d, median: %d" % (np.mean(finals), np.median(finals))) | |
w("%d%% of the samples earned money" % (len(finals[finals > 10000]) * 100 / ITERATIONS)) | |
w("%d%% of the samples got bankrupt" % (len(finals[finals == 0]) * 100 / ITERATIONS)) | |
plt.hist(finals, bins=100) | |
plt.savefig(__file__.replace(".py", ".png")) |
Interesting! Depending on the games you play, different strategies can be effective. For example, in blackjack, there is a basic strategy that optimizes decision-making based on your cards and the dealer's cards. In general, it's essential to learn everything about the game you plan to play and do it on reputable and licensed online platforms like these casinos. Also, a small piece of advice is to set a fixed bet size and stick to it throughout the entire game. This can help manage your bankroll and avoid losses.
This is just a great casino strategy, thank you! I know a place where you can apply this strategy and win big money!!! On the site: reddogcasino.com you can really get a lot of money just by playing your favourite slot machines! I recommend this site to everyone to play there, because nowadays it will be difficult to find a casino of this quality!
In my trustworthy view, visiting a satta matka dp boss, the first thing that caught my attention was its straightforward interface. The platform is designed to be user-friendly, allowing easy access to various games and betting options. This simplicity is great for newcomers, though seasoned players might seek more advanced features. You can learn it by yourself!
Good code, I like it