A very well known result in probability theory is the Central Limit Theorem, which states that the sum of i.i.d. random variables converges in distribution and at a given speed to a normal distribution. Let $(X_1, \dots, X_n)$ be a sample of i.i.d. random variables in $L^2$ with expected value $$S_n := \frac{X_1 + \dots + X_n}{n}$$ We know by the Strong Law of Large Numbers that this quantity converges in probability and a.s. to the expected value $\mu$. The CLT states that $$\sqrt n \left(S_n - \mu \right) \xrightarrow{\mathcal{L}} \mathcal{N}(0, \sigma^2)$$ In other words the average of $n$ independent realizations of a random variable converges to a normal distribution at speed $\sqrt{n}$. We give here a tool to verify that when $n$ grows, the variable $\sqrt{n}(S_n - \mu)$ approximates more and more precisely a normal distribution.
The seed used to initialize the pseudorandom number generator changes at each call of the algorithm if we let the variable seed=0. If we choose an integer different from zero, this seed will be taken to initialize the pseudorandom generator. This can be useful when we want to reproduce twice the same simulation.
Let $Y_n=\sqrt n\left(S_n−\mu\right)$ and let $\left(Y_n^k\right)_{k\geq 0}$ i.i.d. random variables such that $Y_n^k \sim Y_n$ for each $k\geq 0$. In order to visualize the convergence to the normal distribution $\mathcal{N}\left(0,\sigma^2\right)$, we make 1000 simulations of $Y_n$ i.e. $\left(Y^1_n,…,Y^{1000}_n\right)$ and we plot them in an normed histogram with a fixed number of bins.
We notice that for a number of random realizations $n=1$ we obtain an approximation of the distribution of the centered random variable.
We have to set the number of realizations $n$ of the random variable and the number of bins in the histogram.