Binomial distribution with random parameter uniformly distributed

A way to avoid using pre-knowledge about Beta integrals (for a more conceptual explanation, see the second part of this post) is to compute the generating function of $X$, that is, $$ \mathbb E(s^X)=\sum_{k=0}^ns^k\mathbb P(X=k)=\int_0^1\sum_{k=0}^n\binom{n}ku^k(1-u)^{n-k}s^k\mathrm du. $$ By the binomial theorem, $$ \sum_{k=0}^n\binom{n}k(su)^k(1-u)^{n-k}=(1-(1-s)u)^n, $$ hence $$ \mathbb E(s^X)=\int_0^1(1-(1-s)u)^n\mathrm du\stackrel{[v=1-(1-s)u]}{=}\frac1{1-s}\int_s^1v^n\mathrm dv=\frac{1-s^{n+1}}{(n+1)(1-s)}, $$ that is, $$ \mathbb E(s^X)=\frac1{n+1}\sum_{k=0}^ns^k. $$ This formula should make apparent the fact that $X$ is uniform on $\{0,1,2,\ldots,n\}$...


...But the "real" reason why $X$ is uniform might be the following.

First, the distribution of a sum of i.i.d. Bernoulli random variables is binomial. Second, if $V$ is uniform on $[0,1]$, the random variable $\mathbf 1_{V\leqslant u}$ is Bernoulli with parameter $u$. Hence, if $(U_i)_{1\leqslant i\leqslant n}$ is i.i.d. uniform on $[0,1]$, the random variable $\sum\limits_{i=1}^n\mathbf 1_{U_i\leqslant u}$ is binomial with parameter $(n,u)$.

Thus, $X$ may be realized as $X=\sum\limits_{i=1}^n\mathbf 1_{U_i\leqslant U_{n+1}}$ where $(U_i)_{1\leqslant i\leqslant n+1}$ is i.i.d. uniform on $[0,1]$. The event $[X=k]$ occurs when $U_{n+1}$ is the $(k+1)$th value in the ordered sample $(U_{(i)})_{1\leqslant i\leqslant n+1}$. By exchangeability of the distribution of $(U_i)_{1\leqslant i\leqslant n+1}$, $U_{n+1}$ has as much chances to be at each rank from $1$ to $n+1$. This fact means exactly that $X$ is indeed uniform on $\{0,1,2,\ldots,n\}$.


The integral $$\int_0^1 x^\alpha (1 - x)^\beta dx$$ has a well-know representation in terms of $\Gamma$ functions. In the integer case, it boils down to factorials.


Hint: Integrating by parts:

$$\int_0^1 u^k (1-u)^{n-k} \text{d}u = \frac{n-k}{k+1}\int_0^1 u^{k+1} (1-u)^{n-k-1} du$$
so repeat until the exponent of $(1-u)$ reduces to $0$ and you have $$\frac{1}{n \choose k} \int_0^1 u^{n} \text{d}u$$