[PYTHON] Is the lottery profitable? ~ LOTO7 and the law of large numbers ~

Introduction

The question is, "Is the lottery profitable?"

** Not profitable. ** **

The lottery is a business in which the profits of the organizer are extremely large. The return rate of the winning amount is less than 50% [^ 1]. This is an overwhelmingly low value compared to around 75% for horse racing, bicycle racing, boat racing, and auto racing. Moreover, since winning is decided at random, it is impossible to predict like horse racing. Writer Akira Tachibana describes this as "taxes levied on fools."

However, if there is a chance of winning, it will be the case of buying in small lots with large random fluctuations in the winning amount. There is a "law of large numbers" in probability theory. The law is that when you extract a sample from a probability distribution and average it, the average converges to the true average of the probability distribution. Then, ** If the number of samples is small, the possibility of recovering due to random fluctuations may increase. ** I will check this.

environment

Experiment

There are various lottery tickets, but this time I chose LOTO7. The reason is that the first prize is extremely expensive and highly topical, and it is truly "lottery-like." I also didn't think about carryover this time because I wanted to consider a general example. We do not consider changes in the winning amount depending on the number of winning units. Below, we have created a class to calculate the winning amount of Loto 7.

import numpy as np

class Loto7:
    """
Class to calculate the winning amount of Loto 7
    """
    def __init__(self, main_nums, bonus_nums):
        self.main_nums = set(main_nums) #This number
        self.bonus_nums = set(bonus_nums) #Bonus numbers
        
    def prize_amount(self, nums=None):
        nums = self.rand() if nums is None else set(nums)
        diff_main = self.main_nums & nums
        len_main = len(diff_main) #Number of matches with this number
        diff_bonus = self.bonus_nums & nums
        len_bonus = len(diff_bonus) #Number of matches with bonus numbers

        if len_main == 7: # 1st prize
            return 600_000_000
        if len_main == 6: # 2nd and 3rd
            return 7_300_000 if len_bonus == 1 else 730_000
        if len_main == 5: # 4th
            return 9_100
        if len_main == 4: # 5th
            return 1_400
        if len_main == 3 and len_bonus > 0: # 6th
            return 1_000
        else:
            return 0
        
    def rand(self): #Choose a random number
        r = np.random.choice(np.arange(1,38), 7, replace=False)
        return set(r)

Using the class defined above, we will randomly select a number and calculate the winning amount. The calculation method is as follows.

  1. Assuming that you bought n lottery tickets with random numbers, give the total winning amount
  2. Divide it by n to get the amount per bottle
  3. Repeat the above for a fixed number to get the distribution of the winning amount per bottle
  4. For the above, try n with various values

In addition, the winning numbers, this number and the bonus number, have been fixed. As an actual procedure, these numbers are considered to be randomly determined, so considering the relationship with the numbers determined by the purchaser, I thought that it could be fixed.

lt7 = Loto7([1,2,3,4,5,6,7], [8,9]) #This number, which is the winning number, and the bonus number are fixed
n_lots = list(range(1,10)) + list(range(10,30,2)) + [30, 100, 300, 1000] #Number of lottery tickets to buy
reps = 1000 #Number of repeated purchases
prize_amounts = [sum([lt7.prize_amount() for i in range(n)]) / n for n in n_lots for r in range(reps)]
prize_amounts = np.array(prize_amounts).reshape(len(n_lots), reps)

The calculation is now complete. Then, how often are there cases where the purchase price of one LOTO 7 is 300 yen or more? Below, I will draw a graph showing the relationship between the number of purchases and the "proportion of paying back".

recovery_rate = np.apply_along_axis(lambda x: (x >= 300).sum() / len(x), 1, prize_amounts)

plt.plot(n_lots, recovery_rate);
plt.xscale('log')
plt.xlabel('number of LOTO7 tickets')
plt.ylabel('recovery rate')
plt.show()

loto7graph.png

print(n_lots)
print(recovery_rate)

# [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 100, 300, 1000]
# [0.042 0.083 0.104 0.062 0.018 0.024 0.022 0.025 0.019 0.014 0.018 0.017
#  0.022 0.012 0.009 0.024 0.024 0.024 0.024 0.028 0.002 0.008 0.011]

There are two things that can be understood from this.

――The most "recoverable" purchase number is 3 ――In that case, there is a 10% chance that you will be able to recover.

Conclusion.

** Not profitable. ** **

Wise people should stop the lottery!

that's all.

Recommended Posts

Is the lottery profitable? ~ LOTO7 and the law of large numbers ~
Law of large numbers in python
The answer of "1/2" is different between python2 and 3
FAQ: Why is the comparison of numbers inconsistent?
Is there a secret to the frequency of pi numbers?
The impact of Linux page cache attack countermeasures is large and is expected to be prolonged [Translation]
The story of Python and the story of NaN
Is the probability of precipitation correct?
Science "Is Saito the representative of Saito?"
Aggregation and visualization of accumulated numbers
Review the concept and terminology of regression
What is the cause of the following error?
[python] [meta] Is the type of python a type?
The story of trying deep3d and losing
The update of conda is not finished.
The backslash of the Japanese keyboard is "ro"
Create an easy-to-read pdf of laws and government ordinances using the law api