# How we can generate a random vector E=[e_1,e_2,e_3.…,e_N] in R^N such that sum_i^N e_i=T and 0 <= e_i <= d_i AAi in 1,2,3,…,N where d_i specifies the upper bound on each element of the vector. Is this problem over constrained? if yes, any guidance to for relaxation.

How we can generate a random vector $E=\left[{e}_{1},{e}_{2},{e}_{3}.\dots ,{e}_{N}\right]\in {R}^{N}$ such that $\sum _{i}^{N}{e}_{i}=T\phantom{\rule{thickmathspace}{0ex}}$ and $0\le {e}_{i}\le {d}_{i}$ $\mathrm{\forall }i\in 1,2,3,\dots ,N$ where di specifies the upper bound on each element of the vector. Is this problem over constrained?
You can still ask an expert for help

• Questions are typically answered in as fast as 30 minutes

Solve your problem for the price of one coffee

• Math expert for every subject
• Pay only if we can solve it

crearti2d4
An obvious necessary condition is to have $\sum _{i=1}^{N}{d}_{i}\ge T$
If you don't care about choosing uniformly, the simplest is to generate N random numbers $0\le {r}_{i}\le {d}_{i}$, and compute $R=\sum _{i=1}^{N}{r}_{i}$
In the case R<T, increase the ${e}_{i}$ one by one to their maximum until the $\sum _{i=1}^{N}{e}_{i}=T$ as needed. The procedure is guaranteed to work if $\sum _{i=1}^{N}{d}_{i}\ge T$
Otherwise (if R>T), then set ${e}_{i}=T{r}_{i}/R$. Then, by construction,
$\sum _{i=1}^{n}{e}_{i}=\sum _{i=1}^{n}\frac{T{r}_{i}}{R}=\frac{T}{R}\sum _{i=1}^{n}{r}_{i}=T.$