## Runs test

In the pseudo-random number sequence, $x_k<x_{k+1}$s ascending runs and $x_k>x_{k+1}$ is descending runs. Runs test calculates the length of the descending runs or ascending runs in the pseudo-random number sequence, and it determines the nature of the random number from the frequency distribution of the runs.

The frequency distribution $f_1,…,f_5$ of the runs with length $1，…，5$, and the frequency distribution $f_6$of $6$ or more in length of runs from the random number sequence of length $N$, The $V$ statistics is as follows,

$V=\frac{1}{N}\underset{1\leq i,j\leq 6}{\sum } \left(f_i-N b_i\right) \left(f_j-N b_j\right)a_{i j}$

where

$a_{i j}=\left[ \begin{array}{cccccc} 4529.35 & 9044.9 & 13568. & 18091.3 & 22614.7 & 27892.2 \\ 9044.9 & 18097. & 27139.5 & 36186.7 & 45233.8 & 55788.8 \\ 13568. & 27139.5 & 40721.3 & 54281.3 & 67852. & 83684.6 \\ 18091.3 & 36186.7 & 54281.3 & 72413.6 & 90470.1 & 111580. \\ 22614.7 & 45233.8 & 67852. & 90470.1 & 113262. & 139476. \\ 27892.2 & 55788.8 & 83684.6 & 111580. & 139476. & 172860. \\ \end{array} \right]$

$b_i=\left[ \begin{array}{cccccc} \frac{1}{6} & \frac{5}{24} & \frac{11}{120} & \frac{19}{720} & \frac{29}{5040} & \frac{1}{840}\\ \end{array} \right] \\ \\$

Also, the above approximate expression holds when $N>10^4$. If a pseudo random number sequence is uniform, $V$ is according to a $\chi^2$ distribution with 6 degrees of freedom asymptotically.

Reference:
• JIS Z 9031:2012, Procedure for random number generation and randomization

Back to this TOP