title: Randomly sample an array with a fixed number of zeros
body: <p>I have optimized code to randomly sample an array containing -1s, 0s and 1s with probabilities 1/4,1/2,1/4. It looks like</p>
  
  <pre><code>#define n (12)
  unsigned int x,y=34353,z=57768,w=1564; //PRNG seeds
  /* xorshift PRNG
   * Taken from https://en.wikipedia.org/wiki/Xorshift#Example_implementation
   * Used under CC-By-SA */
  u_int32_myRand() {
      unsigned int t;
      t = x ^ (x &lt;&lt; 11);
      x = y; y = z; z = w;
      return w = w ^ (w &gt;&gt; 19) ^ t ^ (t &gt;&gt; 8);
  }
  
  x=(int)time(NULL); //seed PRNG
  unsigned int k
  int F[n];
  for(k=0; k&lt;n; k++) {
        F[k]=(1-(myRand()&amp;3))%2;  
      }
  </code></pre>
  
  <p>How can I modify this so that it only returns arrays that have exactly n/3 zeros in them and still  have it fast?</p>