# 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
xp = np.random.seed (1234567)
# generate 50 random integers from 1 to 50 using random.randint() and make a
# frequency histogram
h = np.random.randint (low = 1, high = 50, size = 50)
print (h)
import matplotlib.pyplot as plt
h = [20 , 7, 6, 35, 33, 33, 14, 15, 27, 36, 12, 46, 49, 3, 6, 28, 31, 48, 20, 19, 8, 37, 40, 23,
36, 34, 33, 24, 47, 23, 21, 43, 39, 13, 1, 41, 49, 16, 42, 23, 13, 26, 13, 38, 16, 41, 13, 40,
28, 21]
plt.hist (h, bins = 10)
plt.show ()
# generate 10000 random integers from 1 to 50 using random.randint() and make a
# frequency histogram
# compare with previous histogram
x = np.random.randint (low = 1, high = 50, size = 10000)
print (x)
x = np.random.randint (low = 1, high= 50, size = 10000)
print (x)
plt.hist (x, bins = 10)
plt.show ()
# generate 1000 floating point numbers uniformly distributed from 1 to 100 and make a
# frequency histogram
x = np.random.uniform ( low = 1, high = 100, size = 1000)
print (x)
plt.hist (x, bins = 10)
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
x = np.random.normal (50, 5, size = 1000)
print (x)
plt.hist (x, bins = 10)
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
x = np.random.normal (50, 5, size = 1000)
print (x)
plt.hist (x, bins = 1000)
plt.show()
# import random and set seed
s = np.random.seed(1234567)
# Simulate drawing a single ball; each ball has a number from from 1 to 50
x = np.random.randint(low = 1, high = 50)
# Simulate drawing 100 balls and keep track of the number of balls
# that have a number less than 25
x = np.random.randint (low = 1, high = 50, size = 100)
a = 25
b = 0
for i in x:
if i < a:
b = b + 1
print (f"Balls less than 25 are: {b}")
# Calculate discrete probability that you will draw a ball with a number <25 using 10,000
# simulations
x = np.random.randint (low = 1, high = 50, size 10000)
a = 25
b = 50
for i in x:
if i < b:
print ()
# 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
def ball():
x = np.random.randint (low = 1, high = 50)
if x < 25:
print ("true")
elif x >= 56:
print ("false")
print (x)
ball ()