Spectral test

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
Three-dimensional plot of 100,000 values generated with RANDU. Each point represents 3 consecutive pseudorandom values. It is clearly seen that the points fall in 15 two-dimensional planes.

The spectral test is a statistical test for the quality of a class of pseudorandom number generators (PRNGs), the linear congruential generators (LCGs).[1] 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.[2] The spectral test compares the distance between these planes; the further apart they are, the worse the generator is.[3] 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,[4] this is by far the most powerful test known, because it can fail LCGs which pass most statistical tests. The IBM subroutine RANDU[5][6] 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 5 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

[edit | edit source]

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[7]: 3  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.[7]: 3 

L'Ecuyer 1991 further introduces two measures corresponding to the minimum of fd across a number of dimensions.[8] 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 the fd is calculated differently in these two cases, necessitating separate values.[7]: 13  They further define a "harmonic" weighted average figure of merit, d+(m,a) (and d*(m,a)).[7]: 13 

Examples

[edit | edit source]

A small variant of the infamous RANDU, with xn+1=65539xnmod229 has:[4]: (Table 1) 

d 2 3 4 5 6 7 8
ν2
d
536936458 118 116 116 116
μd 3.14 10−5 10−4 10−3 0.02
fd[a] 0.520224 0.018902 0.084143 0.207185 0.368841 0.552205 0.578329

The aggregate figures of merit are: 8*(65539,229)=0.018902, 8*(65539,229)=0.330886.[a]

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.[9]

d 2 3 4 5 6 7 8
ν2
d
4243209856 2072544 52804 6990 242
μd[b] 3.10 2.91 3.20 5.01 0.017
fd[a] 0.462490 0.313127 0.457183 0.552916 0.376706 0.496687 0.685247

The aggregate figures of merit are: 8*(69069,232)=0.313127, 8*(69069,232)=0.449578.[a]

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.[7]: 14–5  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.[7]: 14 
  • For an MCG (c = 0), 0x1e92d (125229). 8*=0.6623, 8*=0.7497.[7]: 14 

Additional illustration

[edit | edit source]
Despite the fact that both relations pass the Chi-squared test, the first LCG is less random than the second, as the range of values it can produce by the order it produces them in is less evenly distributed.

References

[edit | edit source]
  1. ^ a b c d Calculated using software from Steele & Vigna (2020), program "mspect" (src/spect.cpp, multiplicative mode).
  2. ^ Calculated from ν2
    d
    reported by Marsaglia.
  1. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value)..
  2. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
  3. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
  4. ^ a b Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value)..
  5. ^ IBM, System/360 Scientific Subroutine Package, Version II, Programmer's Manual, H20-0205-1, 1967, p. 54.
  6. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
  7. ^ a b c d e f g Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value). Associated software and data at https://github.com/vigna/CPRNG.
  8. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value). Be sure to read the Errata as well.
  9. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).

Further reading

[edit | edit source]
  • Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value). – lists the fd (notated as Ss in this text) of many well-known LCGs
    • An expanded version of this work is available as: Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).