Main Content

Pseudorandom and Quasirandom Number Generation

Generate pseudorandom and quasirandom sample data

In certain circumstances, the common methods of random number generation are inadequate to produce the desired samples. Statistics and Machine Learning Toolbox™ offers several alternative methods to generate pseudorandom and quasirandom numbers. Quasirandom numbers, also known as low discrepancy sequences, generate each successive number as far away as possible from existing numbers in the set. This approach avoids clustering and can speed up convergence, but quasirandom numbers are generally too uniform to pass randomness tests. Pseudorandom numbers are less uniform than quasirandom numbers and may be more appropriate for applications that require greater randomness. Use the slice sampler, the Hamiltonian Monte Carlo sampler, or the Metropolis-Hastings Markov chain sampler to generate pseudorandom samples by drawing from a statistical distribution.

If the available parametric probability distributions do not adequately describe your data, you can use a flexible distribution family instead. The Pearson and Johnson flexible distribution families fit a model based on the location, scale, skewness, and kurtosis of the sample data. Once you fit a distribution to your data, you can generate pseudorandom numbers from that distribution.


expand all

slicesampleSlice sampler
mhsampleMetropolis-Hastings sample
hmcSamplerHamiltonian Monte Carlo (HMC) sampler
pearsrndPearson system random numbers
johnsrndJohnson system random numbers


expand all

haltonsetHalton quasirandom point set
qrandstreamQuasirandom number stream
sobolsetSobol quasirandom point set
HamiltonianSamplerHamiltonian Monte Carlo (HMC) sampler