I am trying to create a list of numbers, which are created as follows: A sum of 12 random numbers between 0 and 1 and subtract 6 from it. This counts as 1 random value which I will call y. I'm trying to create a list of random y values, which once I succeed in making, will create a histogram from this list to check the mean value theorem. However, when I try running the code I have pasted below, I get a list of 10 repeated values for y, when I'm trying to get 10 random values. How can I fix this code?
import numpy as np
import math
import random
def makelist(x,minnum,maxnum):
l = []
for col in range(x):
l.append(random.uniform(minnum,maxnum))
return l
def ysum(x,minnum,maxnum):
m = makelist(x,minnum,maxnum)
n = []
n.append(math.fsum(m)-6)
return n
def yhist(x,y,minnum,maxnum):
h = []
f = ysum(x,minnum,maxnum)
for i in range(y):
h.append(f)
return h
print(yhist(12,10,0,1))
Attempted to create random number generation values appended to list, however resulted in repeated numbers.
Aucun commentaire:
Enregistrer un commentaire