# 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
x = np.random.seed (123456)
# generate 50 random integers from 1 to 50 using random.randint() and make a
# frequency histogram
randomvalues = np.random.randint(1,50,50)
plt.hist(randomvalues,5)
# generate 10000 random integers from 1 to 50 using random.randint() and make a
# frequency histogram
# compare with previous histogram
rvalues = np.random.randint(1,50,10000)
plt.hist(rvalues,5)
# generate 1000 floating point numbers uniformly distributed from 1 to 100 and make a
# frequency histogram with 5 bars
xvalues = np.random.uniform (size = 1000)
xvalues = 1 + (100-1)*xvalues
plt.hist(xvalues, 5)
# generate 1000 floating point numbers normally distributed about a mean of 50
# with a standard deviation of 5 and make a frequency histogram
norm = np.random.normal(size = 1000)
norm = 50 + (5)*norm
plt.hist(norm, 5)
# 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
norm2 = np.random.normal(size = 1000)
norm2 = 50 + (5)*norm2
plt.hist(norm, 5, density = True)
# import random and set seed
x = np.random.seed (123456)
# Simulate drawing a single ball; each ball has a number from from 1 to 50
ball = np.random.randint(1,50,1)
print(ball)
# Simulate drawing 100 balls and keep track of the number of balls
# that have a number less than 25
counter = 0
for i in range(0,100) :
ballnum = np.random.randint(1,50,1)
if (ballnum < 25) :
counter = counter + 1
print(counter)
# Calculate discrete probability that you will draw a ball with a number <25 using 10,000
# simulations
counter = 0
for i in range(0,10000) :
ballnum = np.random.randint(1,50,1)
if (ballnum < 25) :
counter = counter + 1
print(f"{counter/10000} is the discrete probability")
# 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
numberoftimes = 1
for i in range (0, numberoftimes) :
ball = np.random.randint(1,50,1)
if(ball < 25) :
print(f"True")
else :
print(f"False")