cpp/numeric/random/piecewise constant distribution

produces random floating-point numbers, which are uniformly distributed within each of the several subintervals $[b i, b i+1)$, each with its own weight $w i$. The set of interval boundaries and the set of weights are the parameters of this distribution.

The probability density for any $b i ≤ x <b i+1$ is $$, where $S$ is the sum of all weights.

satisfies all requirements of.