Recycling a uniform random variable after discrete sampling (source code)

= Recycling a uniform random variable after discrete sampling
{title2=$V=(U-C_{J-1})/w_J$}

For positive <mixture weights> $w_j$ summing to one, set $C_j=\sum_{i\leq j}w_i$ and choose $J=j$ when $C_{j-1}\leq U<C_j$, where $U$ has a <uniform distribution>. Then $V=(U-C_{J-1})/w_J$ has a <uniform distribution> independently of $J$: for $0\leq v\leq1$, $\Pr(J=j,V\leq v)=w_jv$. This permits exact <finite mixture model> sampling with a recycled continuous <random variable>.