I don't really know how to ask this question.
Basically my problem is that I'm trying to generate a list of random numbers, and do it twice.
I have put my code inside a function and I'm just calling it as many times as I need it. Ideally, it returns a different set of random numbers both times.
NoOfRoles = 6
randomlist1 = randomroles2(NoOfRoles)
randomlist2 = randomroles2(NoOfRoles)
def randomroles2(NoOfRoles, CurrentList = [])
weights = {
"A" : 0.5,
"B" : 1,
"C" : 1.5
}
TotalWeighted = 2.0
random1 = random.random()*TotalWeighted
value = TotalWeighted
for item in weights:
value -= weights[item]
if value <= 0:
CurrentList.append(item)
print("I am doing this function")
return CurrentList
What I have discovered is happening is that the function randomroles2() is running once, and then outputting the same value for both randomlist1 and randomlist2, and every subsequent time it's called on the same compile of the script.
I've put some print() lines in there, and python isn't even running subsequent callings of randomroles2() - assuming NoOfRoles stays the same. It is just assuming the output is the same without checking and providing that instead.
Is there a way to force python to run the function again? I am on Python 3.8.5.
Aucun commentaire:
Enregistrer un commentaire