Generate Evenly Distributed Pattern Based on Weights
Normalize $W$ by calculating the greatest common divisor of $W$ and dividing every element by it.

Then just repeatedly iterate over $W$ in order, and if $W_i &gt; 0$ subtract $1$ from it and output $A_i$. You stop when all $W_i = 0$.

If $1, 2, 2, 3, 3, 1, 2, 2, 3, 3, \dots $ in your example is also fine then just output $W_i$ copies of $A_i$ after normalization.