In unbiased coin flip H or T occurs 50% of times.
But I want to simulate coin which gives H with probability ‘p’ and T with probability ‘(1-p)’.
something like this:
def flip(p): '''this function return H with probability p''' # do something return result >> [flip(0.8) for i in xrange(10)] [H,H,T,H,H,H,T,H,H,H]
random.random()returns a uniformly distributed pseudo-random floating point number in the range [0, 1). This number is less than a given numberpin the range [0,1) with probabilityp. Thus:Some experiments: