The absolute reason why you can't make money by gambling is the "law of large numbers". From Kotobank below
The law of large numbers is a theorem in which the number of occurrences of an event approaches a theoretical value by repeating many trials, such as the number of appearances being close to 1/2 by repeating coin throwing many times.
Let's demonstrate this with python.
large_num.py
#Random number generator library
import random
#Library for math calculations
import math
#Set the number of trials
max_try = int(input('Enter the maximum number of attempts (10 is the power of the input value)) :\n'))
#Set pattern
pattern = int(input('Please enter what fraction you want to calculate: \n'))
#Calculate theoretical probabilities
theory = (1 / pattern) * 100
print(theory)
print('\n{0}The probability of getting 1 out of the number of streets is theoretical{1}%\n'.format(pattern,theory))
print('Calculation start!!\n')
for i in range(1,max_try) :
#Set the number of trials
try_num = pow(10,i)
#Initialize count
count = 0
for x in range(try_num):
#Random number generation
dice = random.randint(1,pattern)
#Judge 1
if dice == 1 :
count += 1
#Calculate probability
result = (count / try_num) * 100
#Print the result
out = '{0}The probability of getting 1 in times is{1}%The difference from the theoretical value{2}%'.format(try_num,result,math.fabs(result - theory))
print(out)
Recommended Posts