from random import random def bernoulli(): if random()<0.7: return(1) else: return(0) >>> bernoulli() 1 >>> bernoulli() 0