The spectral test is a statistical test for the quality of a class of pseudorandom number generators (PRNGs), the linear congruential generators (LCGs). LCGs have a property that when plotted in 2 or more dimensions, lines or hyperplanes will form, on which all possible outputs can be found. The spectral test compares the distance between these planes; the further apart they are, the worse the generator is. As this test is devised to study the lattice structures of LCGs, it can not be applied to other families of PRNGs. According to Donald Knuth, this is by far the most powerful test known, because it can fail LCGs which pass most statistical tests. The IBM subroutine RANDU LCG fails in this test for 3 dimensions and above. Let the PRNG generate a sequence u1,u2,…. Let 1/νt be the maximal separation between covering parallel planes of the sequence {(un+1:n+t)∣n=0,1,…}. The spectral test checks that the sequence ν2,ν3,ν4,… does not decay too quickly. Knuth recommends checking that each of the following five numbers is larger than 0.01: μ2=πν22/m,μ3=43πν33/m,μ4=12π2ν44/m,μ5=815π2ν55/m,μ6=16π3ν66/m, where m is the modulus of the LCG.
Figures of merit Knuth defines a figure of merit, which describes how close the separation 1/νt is to the theoretical minimum. Under Steele & Vigna's re-notation, for a dimension d, the figure fd is defined as fd(m,a)=νdγd1/2md, where a,m,νd are defined as before, and γd is the Hermite constant of dimension d. γd1/2md is the smallest possible interplane separation. L'Ecuyer 1991 further introduces two measures corresponding to the minimum of fd across a number of dimensions. Again under re-notation, ℳd+(m,a) is the minimum fd for a LCG from dimensions 2 to d, and ℳd∗(m,a) is the same for a multiplicative congruential pseudorandom number generator (MCG), i.e. one where only multiplication is used, or c=0. Steele & Vigna note that fd is calculated differently in these two cases, necessitating separate values. They further define a "harmonic" weighted average figure of merit, ℋd+(m,a) (and ℋd∗(m,a)).
Examples A small variant of the infamous RANDU, with xn+1=65539xnmod229, has:
The aggregate figures of merit are: ℳ8∗(65539,229)=0.018902, ℋ8∗(65539,229)=0.330886. George Marsaglia (1972) considers xn+1=69069xnmod232 as "a candidate for the best of all multipliers" because it is easy to remember, and has particularly large spectral test numbers.
The aggregate figures of merit are: ℳ8∗(69069,232)=0.313127, ℋ8∗(69069,232)=0.449578. Steele & Vigna (2020) provide the multipliers with the highest aggregate figures of merit for many choices of m = 2n and a given bit-length of a. They also provide the individual fd values and a software package for calculating these values. For example, they report that the best 17-bit a for m = 232 is:
For an LCG (c ≠ 0), 0x1dab5 (121525). ℳ8+=0.6403, ℋ8+=0.6588. For an MCG (c = 0), 0x1e92d (125229). ℳ8∗=0.6623, ℋ8∗=0.7497.
Additional illustration
References
Further reading Entacher, Karl (January 1998). "Bad subsequences of well-known linear congruential pseudorandom number generators". ACM Transactions on Modeling and Computer Simulation. 8 (1): 61–70. doi:10.1145/272991.273009. – lists the fd (notated as Ss in this text) of many well-known LCGs An expanded version of this work is available as: Entacher, Karl (2001). "A Collection of Selected Pseudorandom Number Generators With Linear Structures - extended version".



