names.append(name)
cumprobs.append(cumprob)
cumprobs = [(p / cumprobs[-1]) for p in cumprobs]
N = 1000
selected = [names[bisect.bisect(cumprobs, random.random())] for i in range(N)]
print('\n'.join(selected))
Choosing elements from python list based on probability