I am from an imaginary country where we have a lottery every week. The winner gets 1 millon dollars. The agency, every week, issues 1.1 million tickets, 1 dollar each. The winner gets 1 million, government gets 100k.
I have a budget of $n$ dollars, and decide to buy an $m$ percent of the tickets, for $t$ weeks.
Example: I have a budget of 1 million dollars, I decide buying 1% of the tickets, every week, for 100 weeks.
Does my likelihood of winning increase every week? (I remember the answer was no from my math classes - but cant explain why)
What is the probability distribution of winning at least once from week 0 to 100?
How fast/or slow will my 1 million dollars shrink (dollar/week)
Does the rate my money shrinks, change with different percentage of tickets I buy? Why?
And when (which week) will I win the lottery?
I wrote a python code for investigating these questions, This Python code simulates a scenario where a person plays a weekly lottery over a specified number of weeks, buying a certain percentage of available tickets each week. The goal is to calculate the probability of winning and visualize how the budget changes over time.
Key variables are initialized, including the total number of tickets (num_tickets), cost of each ticket (ticket_cost), the lottery prize (prize), the initial budget (initial_budget), the percentage of tickets to be bought each week (percentage_tickets_bought), and the number of weeks for the simulation (num_weeks).
The function simulate_week models a single week of the lottery, determining the number of tickets bought based on the specified percentage, reducing the budget accordingly, simulating the lottery draw, and checking if any of the purchased tickets won. The function returns a boolean indicating if a win occurred and the remaining budget.
The function simulate_lottery runs the simulate_week function over the desired number of weeks, tracking wins and the budget over time.
Finally, the simulate_ensemble function runs the simulate_lottery function multiple times to generate an ensemble of simulations, and the results are averaged to calculate the average budget and winning probability over time.
The average budget and winning probability over time are then plotted.
import numpy as np
import matplotlib.pyplot as plt
# Initialize parameters
num_tickets = 1_100_000
ticket_cost = 1
prize = 1_000_000
initial_budget = 1_000_000
percentage_tickets_bought = 0.01
num_weeks = 100
# Define a single week's simulation
def simulate_week(budget):
tickets_bought = int(num_tickets * percentage_tickets_bought)
budget -= tickets_bought * ticket_cost
winning_ticket = np.random.randint(num_tickets)
if winning_ticket < tickets_bought:
budget += prize
return True, budget
else:
return False, budget
# Run the simulation for a number of weeks
def simulate_lottery(num_weeks, budget):
wins = []
budget_over_time = []
for i in range(num_weeks):
win, budget = simulate_week(budget)
wins.append(win)
budget_over_time.append(budget)
return wins, budget_over_time
# Ensemble simulation
def simulate_ensemble(num_weeks, num_simulations):
all_wins = []
all_budgets = []
for _ in range(num_simulations):
wins, budget_over_time = simulate_lottery(num_weeks, initial_budget)
all_wins.append(wins)
all_budgets.append(budget_over_time)
return all_wins, all_budgets
# Run the ensemble simulation and calculate averages
num_simulations = 1000
all_wins, all_budgets = simulate_ensemble(num_weeks, num_simulations)
average_budget = np.mean(all_budgets, axis=0)
average_win_prob = np.mean(all_wins, axis=0)
# Plot average budget and winning probability over time
plt.figure(figsize=(12, 6))
plt.plot(average_budget)
plt.xlabel('Week')
plt.ylabel('Average Budget')
plt.title('Average Budget over Time across Simulations')
plt.show()
cumulative_wins = np.cumsum(average_win_prob)
cumulative_prob = cumulative_wins / (np.arange(num_weeks) + 1)
plt.figure(figsize=(12, 6))
plt.plot(cumulative_prob)
plt.xlabel('Week')
plt.ylabel('Average Cumulative Winning Probability')
plt.title('Average Cumulative Winning Probability over Time across Simulations')
plt.show()
This code generates two plots: the first shows the average budget over time across all simulations, while the second shows the average cumulative winning probability over time across all simulations. These results provide a probabilistic understanding of the likely outcomes of repeatedly playing the lottery with a fixed strategy over time.
Here is the result of simulation for 1 million, 100 weeks and 1% of the tickets:

