python - Trying to produce different random numbers every time a loop is executed -
srate = [5,5,5] bots = 120 nqueue = 3 tsim = 100 exp = 2 ddistance = 1 lambda = 40 # 120/3 = 40 import random elist=[] avgsrate = 5 def initilization(avgsrate,lambda,exp): return float((lambda/(avgsrate**exp))*(1+(1/10)*(2*(np.random.seed(-28)) - 1))) in range(1,361): elist.append(initilization) i trying produce set of randomly generated numbers between 0 , 1, decimals initialization of simulation, spits out same values every time loop executed, when print elist list of same values. list has <function initialization @ "the number">, me eliminate portion printed list have numbers.
the issue np.random.seed(-28) seeding random generator [documentation] , not return random numbers , getting random number use - np.random.rand() .
example -
return float((lambda/(avgsrate**exp))*(1+(1/10)*(2*(np.random.rand()) - 1))) if want seed random generator, can call before calling for loop calls initilization function.
the function after should -
def initilization(avgsrate,lambda,exp): return float((lambda/(avgsrate**exp))*(1+(1/10)*(2*(np.random.rand()) - 1))) also, 1 more issue, not adding value returned function call list - elist.append(initilization) , adding function reference.
you need change elist.append(initilization(<values parameter>)) call function , append returned value elist .
Comments
Post a Comment