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 trues each false in long run.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -