I saw this question on Zhihu: since the winning rate of each game is 50%, why do so many people finally gamble to ruin their money?

It seems to be quite reasonable, some people just can’t figure out, the odds are 50%, the long-term should be a winner, why would someone lose everything, for this problem we might as well use Python to do a simulation experiment.

Experimental ideas:

  1. Gambling is set to play dice (this word read Tou, four sound, meaning not unexpected) son, guess the size, a day of gambling, each bureau a zhuang a idle, until the idle home lost or casino off work (assuming that the casino will work);
  2. The gambler believes that winning or losing is pure chance time and believes that it is impossible to turn the handle up (or down), so after losing three hands in a row, the gambler will raise his bet by 50%.
  3. The gambler has a total of $1 million in savings and will bring $20,000 in cash for the first time.
  4. Gamblers who run out of money try to make ends meet with loan sharks (a conservative estimate of 5% a month, capped at 3% by the state; casino loan sharks are said to be much higher, but it is not clear how much).
  5. The loan shark pays it back the next day (the average gambler rarely pays it back so quickly, assuming we’re simulating a “disciplined” gambler).

Test steps

1. Create characters

class gambler(): def __init__(self): Self. deposit = 1000000 # deposit = 1000000 # deposit = 1000000 # deposit = 1000000 # deposit = 1000000 # deposit = 1000000 # deposit = 1000000 # deposit = 1000000 #Copy the code
Cathala = gambler()# Cathala.bet = 100000000 Cathala.deposit = 100000000Copy the code





The casino

Geralt = Gambler ()#Geralt is an avid gamblerCopy the code





This is a rabid gambler

2. Create a bet

We’re not playing Quint today. We’re playing dice.





This is the game of chance

Here is a function implementation of the bet:

Bet = 1000# count = 0 gambling_list = []#Copy the code
Def gambling(gambler_a,gambler_b,bet,count): Point = random.randint(2, 12) # guess = random.randint(0, 1) # If (point > 7 and guess == 1) or (point <= 7 and guess == 0): Geralt.bet += bet Cathala. Bet -= bet return True else: Geralt.bet -= bet Cathala. Bet += bet return FalseCopy the code

Men play 100 games

def One_day_gambling(): Geralt.bet = 20000 bet = 1000 count = 0 while True: gambling_list.append(gambling(Cathala, Geralt, bet, count)) count += 1 if count > 3 and gambling_list[count - 3] == gambling_list[count - 2] == gambling_list[count - 1] == False: If Geralt <= -5000 or count >= 100: if Geralt <= -5000 or count >= 100: if Geralt <= -5000 or count >= 100: Break return Geralt. Bet-20000 # returns the debt or profit at the end of each solitary dayCopy the code

Then we kept a record of our wins and losses every day, and then we counted the bankruptcies.

Def record_daily_gambling(): debt = []# record the final profit and loss of each day. If gambling is less than zero, it is necessary to take out loans. Append (n) if sum(debt) <= -1000: return (sum(debt), I)# Return (sum(debt),3000)# def main(): every_example = pd.DataFrame() lost_money = [] bankrupt_time = [] for j in range(1000): m = record_daily_gambling() lost_money.append(m[0]) bankrupt_time.append(m[1]) print(j) every_example['lost_money'] = lost_money every_example['bankrupt_time'] = bankrupt_time every_example.to_csv('experiment_data.csv',index=False,sep=',') if __name__ == "__main__": main()Copy the code

3. Statistics

A total of 1000 people were simulated, among which 167 people were not bankrupt (including 3 people losing money and 164 people making profit) and 833 people were bankrupt, with a bankruptcy rate of 83.3%. Basically, all of them were bankrupt at last. Let’s take a look at the bankruptcy time of each person.







Time distribution of bankruptcy


What about the people who don’t end up broke? How much is the final profit?







The total profit of the non-bankrupt person over eight years


Seems like a lot, right? Let’s read on:

Here’s China’s inflation rate over the last decade (official data) :





The rate of inflation over the last decade






13%

conclusion

  1. The bankruptcy rate of simulated gambling is as high as 83.3%, and half of them go bankrupt within a year.
  2. Because of the randomness of gambling profit, the profit margin is not high, which shows that gambling can not be used as a means to get rich.
  3. The odds of winning the casino are almost zero.