python - Biased coin flipping? -
what simplest (does not have fastest) way biased random choice between true , false in python? "biased", mean either true or false more probable based on probability set.
it's pretty easy and fast:
import random def biased_flip(prob_true=0.5): return random.random() < prob_true
of course if call biased_flip()
you'll true
, false
50% probability each, e.g biased_flip(0.8)
give 8 true
s each false
in long run.
Comments
Post a Comment