The R_TEST function tests the hypothesis that a binary population (a sequence of 1s and 0s) represents a "random sampling". The result is a two-element vector containing the nearly-normal test statistic Z and its associated probability. This two-tailed test is based on the "theory of runs" and is often referred to as the " Runs Test for Randomness."

This routine is written in the IDL language. Its source code can be found in the file ```
r_test.pro
```

in the ```
lib
```

subdirectory of the IDL distribution.

X = [0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, $

1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1]

Test the hypothesis that *
X*
represents a random sampling against the hypothesis that it does not represent a random sampling at the 0.05 significance level.

result = R_TEST(X, R = r, N0 = n0, N1 = n1)

Print the values of the keyword parameters:

PRINT, 'Runs: ', r & PRINT, 'Zeros: ', n0 & PRINT, 'Ones: ', n1

The computed probability (0.0117604) is less than the 0.05 significance level and therefore we reject the hypothesis that *
X*
represents a random sampling. The results show that there are too many runs, indicating a non-random cyclical pattern.