Recently, the game named Genshin Impact become extremely popular across the gamming community, but the rule of wishes is criticized by many player.
Objective: In this mini-project, we aim to obtain a overall probability of getting a 5-star charactors if we have unlimited wishes.
Given rule: standard wishes has 0.6% of probability of 5-star charactors, while guaranteed every for every 90 draws without 5-star charactors.
Method: I am going to simulate 5000 consective wishes for 150 individual trials. The final probability is the average of the probablity of 150 trials.
Result: we have expected probablity of 1.43% for 5-star under a unlimited withes condition.
import numpy as np
import matplotlib.pyplot as plt
import random
import pandas as pd
# experiment setup
n_repeat = 5*10**3
p_success = 0.006
n_trial = 150
def n_repeat_Bernoulli_experiment_wt_guaranteed(n_repeat,p_success):
failure_count = 0
failure_count_ls = []
result_ls = []
prob_ls = []
for k in np.arange(1,n_repeat+1):
# draw trail result from Bernoulli distribution
trail = random.choices([1, 0], weights=(p_success, 1-p_success), k = 1)
# count if fail
if trail == [0]:
failure_count += 1
if trail == [1]:
failure_count = 0
# Guaranteed within 90 draws
if failure_count == 90:
trail = [1]
failure_count = 0
# record result
failure_count_ls.append(failure_count)
result_ls += trail
prob_ls.append(sum(result_ls)/len(result_ls))
return result_ls, failure_count_ls, prob_ls
# collect simulation data
simulation_final = []
for k in np.arange(1, n_trial+1):
_, _, prob_ls = n_repeat_Bernoulli_experiment_wt_guaranteed(n_repeat, p_success)
simulation_final.append(prob_ls[-1])
plt.plot(np.arange(1,n_repeat+1), prob_ls, linewidth=1, alpha = .1)
plt.title('The simulation of probablity of drawing five-star charactors (' + str(n_trial) +'-trial)')
plt.xlabel('# of repetition')
plt.ylabel('probablity of sucess')
plt.yscale('log')
plt.axhline(sum(simulation_final)/len(simulation_final), linewidth=1, color='g')
plt.text(x = n_repeat/2,
y = sum(simulation_final)/len(simulation_final)*1.1,
s = 'p = ' + str(sum(simulation_final)/len(simulation_final)))
As shown in the above graph of the probability along the repeatition, the variance diminishes as increasing repetition and the probablity of drawing five-star charactors converge to the value marked above.
print('Probablity:', sum(simulation_final)/len(simulation_final))
print('Standard deviation:', np.std(simulation_final))
# Additionally:
print("The total probability of the success from standard draws:", 0.6/100)
print("The total probability of the success from guaranteed draws:", 1/90)
print("The total probability of the success from standard draws and guaranteed draws:", 0.6/100 + 1/90)
plt.hist(simulation_final)