# import the library numpy as np
# import the library matplotlib.pyplt as plt
import numpy as np
import matplotlib.pyplot as plt
# set a seed for your calculations so that they are reproducible
np.random.seed(42069)
# generate 50 random integers from 1 to 50 using random.randint() and make a
# frequency histogram
array = []
for i in range (0,50):
x = np.random.randint(1, 50)
array.append(x)
plt.hist(array, 5)
plt.show
# generate 10000 random integers from 1 to 50 using random.randint() and make a
# frequency histogram
# compare with previous histogram
array10k = []
for i in range (0,10000):
x = np.random.randint(1, 50)
array10k.append(x)
plt.hist(array10k, 5)
plt.show
# generate 1000 floating point numbers uniformly distributed from 1 to 100 and make a
# frequency histogram
array1k = []
for i in range (0,100):
x = np.random.randint(1, 100)
array1k.append(x)
plt.hist(array1k, 5)
plt.show
# generate 1000 floating point numbers normally distributed about a mean of 50
# with a standard deviation of 5 and make a frequency histogram
#
norm1k = []
for i in range (0, 1000):
x = np.random.normal(50, 5)
norm1k.append(x)
plt.hist(norm1k, 5)
plt.show
# generate 1000 floating point numbers normally distributed about a mean of 50
# with a standard deviation of 5 and make a density histogram; compare with frequency
# histogram
norm1k_2 = []
for i in range (0, 1000):
x = np.random.normal(50, 5)
norm1k_2.append(x)
plt.hist(norm1k_2, 5, density=True)
plt.show
# import random and set seed
import numpy as np
np.random.seed(8008)
# Simulate drawing a single ball; each ball has a number from from 1 to 50
ball = np.random.randint(1, 50)
# Simulate drawing 100 balls and keep track of the number of balls
# that have a number less than 25
count = 0
for i in range (0, 100):
x = np.random.randint(1, 50)
if (x < 25):
count += 1
print(count)
# Calculate discrete probability that you will draw a ball with a number <25 using 10,000
# simulations
count = 0
for i in range (0, 10000):
x = np.random.randint(1, 50)
if (x < 25):
count += 1
prob = count/10000
print (prob)
# Now suppose you are playing a game where you draw a ball. You win if you get a number
# <25 and lose otherwise. Write a function which draws a single ball and returns True
# if the number is <25 and false if it is >= 25
# Test out your function
ball = np.random.randint(1, 50)
if (ball < 25):
print(f"Drew {ball}. You Win!")
else:
print(f"Drew {ball}. You lose...")