Spacing Distribution of Random Numbers

Initializing live version
Download to Desktop

Requires a Wolfram Notebook System

Interact on desktop, mobile and cloud with the free Wolfram Player or other Wolfram Language products.

This Demonstration shows that the spacing distribution of a sorted sequence of random numbers sampled from a uniform probability distribution in the interval always follows an exponential (Poisson) distribution. This is a fundamental result in the spectral theory of random matrices (from random matrix theory), since the eigenvalue spectra of quantum systems with regular classical counterparts have Poisson-level spacing distributions [1, 2].


Use the slider to set the number of generated random numbers. The normalized spacings are then fitted to an exponential distribution to find the value of the decay parameter using the built-in Wolfram Language function FindDistributionParameters; the goodness-of-fit test is performed using the DistributionFitTest object function and related options used in the code; in particular, use the radio buttons to choose among six different statistical tests available for the fitted distribution.


Contributed by: Jessica Alfonsi  (May 2021)
(Padova, Italy)
Open content licensed under CC BY-NC-SA



Snapshot 1: same as thumbnail image but with the Anderson–Darling test applied to exponential fitting on 1000 random numbers

Snapshot 2: the Kolmogorov–Smirnov test applied to exponential fitting on 50 random numbers

Snapshot 3: the Pearson chi square test applied to exponential fitting on 5000 random numbers


[1] M. V. Berry, M. Tabor and J. M. Ziman, "Level Clustering in the Regular Spectrum," Proceedings of the Royal Society of London. A. Mathematical and Physical Sciences, 356(1686), 1977 pp. 375–394. doi:10.1098/rspa.1977.0140.

[2] T. Timberlake, "Random Numbers and Random Matrices: Quantum Chaos Meets Number Theory," American Journal of Physics, 74(6), 2006 pp. 547–553. doi:10.1119/1.2198883.

Feedback (field required)
Email (field required) Name
Occupation Organization
Note: Your message & contact information may be shared with the author of any specific Demonstration for which you give feedback.