 <p>What about:</p> <pre><code>set.seed(12345) allocation &lt;- NULL block &lt;- sample(c(rep(1,4),rep(2,3)),7) for(i in 1:7){ tallocation &lt;- sample(c(rep(0,block[i]),rep(1,block[i]*2)), 3*block[i]) allocation &lt;- c(allocation, tallocation) } </code></pre>