# import numpy library
import numpy as np

# import pyplot library 
import matplotlib.pyplot as plt

# generate a random number between 0 and 1
np.random.randint(0, 5)

np.random.randint(0, 2, size=10)



# 1000 coin flips
A = np.random.randint(0, 2, size=1000)

# make figure
fig = plt.figure()

# get the axes
ax = plt.axes()

# plot a histogram of the outcomes 
plt.hist(A)

# calculate how many people share the same birthday 
    
def calculate_matches(n):
    outcome = np.random.randint(1, 366, size=n)
    number_of_matches = 0
    for i in range(n):
        for j in range(i+1, n):
            if outcome[i] == outcome[j]:
                number_of_matches += 1
    return number_of_matches
            
party_size = np.arange(10, 2000, 100)
matches = np.zeros_like(party_size)

# calculate for all different party sizes 
for i in range(len(party_size)):
    matches[i] = calculate_matches(party_size[i])
    
print(party_size)
print(matches)

plt.plot(party_size, matches)

# plot that number vs N 

# a coin flip with p = 0.8 
np.random.choice([0, 1], p=[0.8, 0.2])

# 1000 biased coin flips with p = 0.8
B = np.random.choice([0, 1], size=1000, p=[0.8, 0.2])

plt.hist(B)

# 10 coin flips each with success probability p = 0.5
# the output is the number of heads out of 10 total coin flips 
np.random.binomial(10, 0.5)

# we can run the whole binomial experiment for multiple times using the "size" argument
# this means that if we flip 10 coins for 5 different iterations 
# the output would be the number of heads in each iteration
np.random.binomial(10, 0.5, size=5)

# change the number of iterations (size), what do you observe as you increase the size? 
C = np.random.binomial(10, 0.5, size=100)

plt.hist(C)

max_trials = 1000
num_trials = np.arange(max_trials)
avg_array = np.zeros_like(num_trials, dtype=np.double)

for i in range(max_trials):
    random_event = np.array(np.random.choice([1, 2, 3, 4, 5, 6], size=i+1))
    avg_array[i] = np.average(random_event)

plt.plot(num_trials, avg_array)



