[Math] Random numbers correlation

correlationrandomrandom walk

I was doing some random number generator testing when I noticed something about ran1 generator from Numerical Recepies. I generated numbers in range $\left<2.5,7.5\right>$ and wanted to check the randomness of the number series by calculating the sum of products of near neighbours
\begin{equation}C\left(k\right)=\frac{1}{N}\sum_{i=1}^{N}r_ir_{i+k}
\tag{1}
\label{eq:sum}
\end{equation}
for different values of $k$. For large $N$ we can approximate the sum \eqref{eq:sum} with integral
\begin{equation} \frac{1}{N}\sum_{i=1}^{N}r_ir_{i+k} \approx \int_{2.5}^{7.5}dx \int_{2.5}^{7.5}dyP\left(x,y\right)xy
\tag{2}
\label{eq:int}
\end{equation}
$P\left(x,y\right)dxdy$ is the probability of getting numbers in intervals $\left<x,x+dx\right>$ and $\left<y,y+dy\right>$, now we have:
\begin{equation}
\int_{2.5}^{7.5}dx \int_{2.5}^{7.5}dyP\left(x,y\right) = 1
\tag{3}
\label{eq:norm}
\end{equation}
If the distribution given by the generator is uniform, then $P=const.$ and we can calculate it using equation \eqref{eq:norm}.
\begin{equation} 1=P\int_{2.5}^{7.5}dx \int_{2.5}^{7.5}dy = 25P\Longrightarrow P=\frac{1}{25}\end{equation}
Now we plug this into \eqref{eq:int} and get
\begin{equation}
\frac{1}{N}\sum_{i=1}^{N}r_ir_{i+k} \approx 25
\label{eq:aprox}
\end{equation}
Additionally, if the numbers are really random, the deviation from this equation should depend on $N$ as $1/\sqrt N$. So I calculated this for different values of $k$ and noticed that the results are $k$-independent.
graph 1
graph 2

I am not sure what this means. The sum represents a correlation function. How can correlation of elements of a series be the same for 1st and $n$th neighbours?

EDIT Here is the same calculation for a different generator. rand

Best Answer

Assuming the numbers are random, the correlation between pairs at any distance should be independent of the distance. That is not surprising. When you convert the sum to the integral, you should say $$\frac{1}{N}\sum_{i=1}^{N}r_ir_{i+k} \approx \int_{2.5}^{7.5}x\ dx \int_{2.5}^{7.5}y\ dyP\left(x,y\right)xy $$ The way you did it the integral doesn't change if you change the range to $(100,105)$ but the product of two elements has to get much larger.

Related Question