I'm trying to do a simulation on the role of luck in human achievement.
Here is what I intend to do with my code:
- Create 20000 instances of people with randomly generated scores for skill, experience and hard-work(0 to 99), and a luck value(0 to 100).
- Create a total score for each person, with 95% of the average of the skill, experience and hard-work, and 5% of their luck value.
- Select the top 10 persons and record their luck value.
- Iterate the procedure a specified amount of times and find the total average luck of all the people who came top ten in all of the iterations.
Please review the code and tell me if my code is correctly written for the above purpose. I'm skeptical about the pseudo-randomness random library interfering with the results.
import random
class candidate :
def __init__(self):
self.skill = random.uniform(0,99)
self.exp = random.uniform(0,99)
self.work = random.uniform(0,99)
self.luck = random.uniform(0,100)
self.total_score = ((self.skill+self.exp+self.work)/3)*.95+self.luck*0.05
candidate_list = []
candidate_selected_lucks = []
def select():
for i in range (0,20000):
candidate_list.append(candidate())
for m in range(0,10):
_max = 0.0
for j in range (0,len(candidate_list)):
if (candidate_list[j].total_score > _max):
_max = candidate_list[j].total_score
index = j
candidate_selected_lucks .append(candidate_list[index].luck)
print(m,"."," Score : ", candidate_list[index].total_score, " Luck : ", candidate_list[index].luck,"\n")
candidate_list.pop(index)
def find_avg(candidate_selected_lucks):
return sum(candidate_selected_lucks)/len(candidate_selected_lucks)
def simulate(N):
for k in range(0,N):
print ("Iteration ",str(k+1),". ")
select()
candidate_list.clear()
print ("average luck is", find_avg(candidate_selected_lucks),"\n")
count = int(input("Enter no of simulations\n"))
simulate(count)
...*0.95
and...*0.05
values either. I'm not fluent in Python, but as a step one I'm sure you could allowluckWeight
to be configured for each instance ofCandidate
. \$\endgroup\$