title: How do I simulate flip of biased coin?
body: <p>In unbiased coin flip H or T occurs 50% of times.</p>
  
  <p>But I want to simulate coin which gives H  with probability 'p' and T with probability '(1-p)'.</p>
  
  <p>something like this:</p>
  
  <pre><code>def flip(p):
     '''this function return H with probability p'''
     # do something
     return result
  
  &gt;&gt; [flip(0.8) for i in xrange(10)]
  [H,H,T,H,H,H,T,H,H,H]
  </code></pre>