title: create binary random matrix with probability in python
body: <p>I am new to python. I want to write a function which generates a random <code>nxm</code> binary matrix with each value 0 for probability p.</p>
  
  <p>What I did.</p>
  
  <pre><code>def randbin(M,N,P):              # function to generate random binary matrix    
      mat = (np.random.rand(M,N)&gt;=P).astype(int)
      return mat  
  
  y = randbin(5,4,0.3)
  </code></pre>
  
  <p>Every time I print the output, I  didn't get the result as per the estimated probability. I don't know what I am doing wrong.</p>