# Unordered sampling with replacement with minimum and maximum bounds [duplicate]

This question already has an answer here:

Suppose we have $R$ containers ($x_1,x_2,\ldots,x_R$) and we have $N$ balls. How many possible distributions we have assuming that $x_{min}\leq x_r\leq x_{max}$ $\forall r\in\{1,2,\ldots,R\}$?

The following is my current work to solve this problem:

Dropping the minimum and maximum constraint, we have

$x_1+x_2+\ldots+x_R=N$

with $x_r\geq0$. We have $\binom {N+R-1}{R-1}$ possible combinations [Reference]

For the minimum constraint, we can define $y_r=x_r-x_{min}$. Therefore, we have

$y_1+y_2+\ldots+y_R=N-R*x_{min}$

with $y_r\geq0$ meaning that $x_r-x_{min}\geq0$ meaning that $x_r\geq x_{min}$. Therefore, we have $\binom {N-R*x_{min}+R-1}{R-1}$ possible combinations.

I am stuck at applying the maximum constraint. Can someone help with applying the maximum constraint?

I do appreciate your help. Thank you