The runs test, or Wald–Wolfowitz test, is a simple non-parametric test for randomness. It can be used to test whether a sequence of values appears to be in random order, against the alternative that the ordering is not random. The test considers the data values relative to the mean or median of the sample or to some function in a simple goodness of fit exercise. When comparing a data sequence using the median value, the sample median is computed and each observed value is assigned a sign, + or -, relative to the median. When comparing to a distribution function, the sequence of values above and below the function value are computed. The sequence of runs of +++.. and --- symbols can then be used in a test to see whether the observed sequence is random, assuming the observations are independent samples. If there are N+ runs of + symbols and N- runs of - symbols, then the total number of runs is N=N++N- and the expected or mean number of runs will be:

Using these formulas the observed number of runs can be standardized (by subtracting the expected value and dividing by the standard deviation, i.e. a normal transform) to produce a z-statistic that is approximately Normally distributed. Note that the test has similarities to the Kolmogorov-Smirnov test but uses the sign of the differences rather than the maximum value of the differences in an ordered set.