title: Binary random array with a specific proportion of ones?
body: <p>What is the efficient(probably vectorized with Matlab terminology) way to generate random number of zeros and ones with a specific proportion? Specially with Numpy?</p>
  
  <p>As my case is special for <code>1/3</code>, my code is:</p>
  
  <pre><code>import numpy as np 
  a=np.mod(np.multiply(np.random.randomintegers(0,2,size)),3)
  </code></pre>
  
  <p>But is there any built-in function that could handle this more effeciently at least for the situation of <code>K/N</code> where K and N are natural numbers?</p>