I am trying to get a random boolean value, but with a weighted percentage. For example, I want the user to pass a percentage (i.e. 60), and the generator will randomly select the true 60% of the time.
What I have:
def reset(percent=50): prob = random.randrange(0,100) if prob > percent: return True else: return False
Is there a better way to do this? It seems inefficient and cumbersome. I don't need this to be perfect, as it is just used to simulate data, but I need it to be as fast as possible.
I searched (Google / SO) and did not find any other questions for this.
rjbez source share