How do I simulate flip of biased coin?
random.random() returns a uniformly distributed pseudo-random floating point number in the range [0, 1). This number is less than a given number p in the range [0,1) with probability p. Thus: def flip(p): return ‘H’ if random.random() < p else ‘T’ Some experiments: >>> N = 100 >>> flips = [flip(0.2) for i in xrange(N)] … Read more