0% found this document useful (0 votes)
5 views

Message

This document contains code that generates random numbers in lists of sizes 10, 100, 1000, 10000, and 100000. It calculates the mean, variance, and standard deviation of each list and plots histograms of the random numbers. It also generates samples from exponential and Poisson distributions of the same sizes and plots histograms to compare the distributions.

Uploaded by

Abdul Abu
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Message

This document contains code that generates random numbers in lists of sizes 10, 100, 1000, 10000, and 100000. It calculates the mean, variance, and standard deviation of each list and plots histograms of the random numbers. It also generates samples from exponential and Poisson distributions of the same sizes and plots histograms to compare the distributions.

Uploaded by

Abdul Abu
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

'''Zubair Dawd 101128532 - Sabir Yeasin 101145857'''

import numpy as np
import matplotlib.pyplot as plt
from random import seed
from random import random

seed(7)

def Average(lst):
return sum(lst) / len(lst)

random10_list = []
random100_list = []
random1000_list = []
random10000_list = []
random100000_list = []

for x in range(10):
value1 = round(random(), 2)
random10_list.append(value1)

print(random10_list)
print("10 Range")
average10 = Average(random10_list)
print("Mean =", round(average10, 2))
print("Variance =", round(np.var(random10_list), 5))
print("Standard Deviation =", round(np.std(random10_list), 5))

plt.hist(random10_list, bins=30)
plt.title('Range 10')
plt.show()

print("----------------------------------------------------------------------------
---------------------------")
print("----------------------------------------------------------------------------
---------------------------")
print("----------------------------------------------------------------------------
---------------------------")

for x in range(100):
value1 = round(random(), 2)
random100_list.append(value1)

print(random100_list)
print("100 Range")
average100 = Average(random100_list)
print("Mean =", round(average100, 2))
print("Variance =", round(np.var(random100_list), 5))
print("Standard Deviation =", round(np.std(random100_list), 5))

plt.hist(random100_list, bins=30)
plt.title('Range 100')
plt.show()
print("----------------------------------------------------------------------------
---------------------------")
print("----------------------------------------------------------------------------
---------------------------")
print("----------------------------------------------------------------------------
---------------------------")

for x in range(1000):
value1 = round(random(), 2)
random1000_list.append(value1)

print(random1000_list)
print("1000 Range")
average1000 = Average(random1000_list)
print("Mean =", round(average1000, 2))
print("Variance =", round(np.var(random1000_list), 5))
print("Standard Deviation =", round(np.std(random1000_list), 5))

plt.hist(random1000_list, bins=30)
plt.title('Range 1000')
plt.show()

print("----------------------------------------------------------------------------
---------------------------")
print("----------------------------------------------------------------------------
---------------------------")
print("----------------------------------------------------------------------------
---------------------------")

for x in range(10000):
value1 = round(random(), 2)
random10000_list.append(value1)

print(random10000_list)
print("10000 Range")
average10000 = Average(random10000_list)
print("Mean =", round(average10000, 2))
print("Variance =", round(np.var(random10000_list), 5))
print("Standard Deviation =", round(np.std(random10000_list), 5))

plt.hist(random10000_list, bins=30)
plt.title('Range 10000')
plt.show()

print("----------------------------------------------------------------------------
---------------------------")
print("----------------------------------------------------------------------------
---------------------------")
print("----------------------------------------------------------------------------
---------------------------")

for x in range(100000):
value1 = round(random(), 2)
random100000_list.append(value1)

print(random100000_list)
print("100000 Range")
average100000 = Average(random100000_list)
print("Mean =", round(average100000, 2))
print("Variance =", round(np.var(random100000_list), 5))
print("Standard Deviation =", round(np.std(random100000_list), 5))

plt.hist(random100000_list, bins=30)
plt.title('Range 100000')
plt.show()

size = 10

sample = np.random.exponential(1/7 ,size)

plt.hist(sample, bins=30)
plt.title("Exponential Distribution for 10")
plt.show()

size = 100

sample = np.random.exponential(1/7,size)

plt.hist(sample, bins=30)
plt.title("Exponential Distribution for 100")
plt.show()

size = 1000

sample = np.random.exponential(1/7,size)

plt.hist(sample, bins=30)
plt.title("Exponential Distribution for 1000")
plt.show()

size = 10000

sample = np.random.exponential(1/7,size)

plt.hist(sample, bins=30)
plt.title("Exponential Distribution for 10000")
plt.show()

size = 100000

sample = np.random.exponential(1/7,size)

plt.hist(sample, bins=30)
plt.title("Exponential Distribution for 100000")
plt.show()

s = np.random.poisson(7, 10)
plt.hist(s, bins=30)
plt.title("Poisson Distribution for 10")
plt.show()
s = np.random.poisson(7, 100)
plt.hist(s, bins=30)
plt.title("Poisson Distribution for 100")
plt.show()

s = np.random.poisson(7, 1000)
plt.hist(s, bins=30)
plt.title("Poisson Distribution for 1000")
plt.show()

s = np.random.poisson(7, 10000)
plt.hist(s, bins=30)
plt.title("Poisson Distribution for 10000")
plt.show()

s = np.random.poisson(7, 100000)
plt.hist(s, bins=30)
plt.title("Poisson Distribution for 100000")
plt.show()

You might also like