Namespaces
Variants
Views
Actions

Pseudo-random number generation

From cppreference.com
< cpp‎ | numeric
Revision as of 12:38, 29 October 2011 by Bregma (Talk | contribs)

Template:cpp/numeric/random/sidebar

The random number library provides a set of generator engines (both pseudo-random number generators, which generate integer sequences with a uniform distribution, and true random number generators if available) and a set of random number distribution classes which convert the uniform distribution of the generator engines into various statistical distributions.

All of the generator engines may be specifically seeded, serialized, and deserialized for use with repeatable simulators.

Contents

Random number engines

Random number engines generate pseudo-random numbers using seed data as entropy source. Several different classes of pseudo-random number generation algorithms are implemented as templates that can be customized.

The choice of which engine to use involves a number of tradeoffs: the linear congruential engine is moderately fast and has a very small storage requirement for state. The lagged Fibonacci generators are very fast even on processors without advanced arithmetic instruction sets, at the expense of greater state storage and sometimes less desirable spectral characteristics. The Mersenne twister is slower and has greater state storage requirements but with the right parameters has the longest non-repeating sequence with the most desirable spectral characteristics (for a given definition of desirable).

Defined in header <random>
implements linear congruential algorithm
(class template)
implements Mersenne twister algorithm
(class template)
implements subtract with carry (a lagged Fibonacci) algorithm
(class template)

Random number engine adaptors

Random number engine adaptors generate pseudo-random numbers using another random number engine as entropy source. They are generally used to alter the spectral characteristics of the underlying engine.

Defined in header <random>
discards some output of a random number engine
(class template)
packs the output of a random number engine into blocks of specified number of bits
(class template)
delivers the output of a random number engine in different order
(class template)

Predefined random number generators

Several specific popular algorithms are predefined.

Template:tdcl list begin Template:tdcl list header Template:tdcl list hitem Template:tdcl list item Template:tdcl list item Template:tdcl list item Template:tdcl list item Template:tdcl list item Template:tdcl list item Template:tdcl list item Template:tdcl list item Template:tdcl list item Template:tdcl list item}} Template:tdcl list end

non-deterministic random number generator using hardware entropy source
(class)

Random number distributions

Random number distributions are post-process the output of an random number engine or adaptors in such a way that resulting output is distributed on a defined statistical probability density function.

Defined in header <random>
 
Uniform distributions
evenly distributes integer random numbers across a range
(class template)
evenly distributes floating-point random numbers across a range
(class template)
evenly distributes floating-point random numbers of given precision across [0, 1)
(function template)
Bernoulli distributions
Produces Template:cpp values on a Bernoulli distribution.
(class)
Produces integer values on a binomial distribution.
(class template)
Produces integer values on a negative binomial distribution.
(class template)
Produces integer values on a geometric distribution.
(class template)
Poisson distributions
Produces integer values on a poisson distribution.
(class template)
Produces real values on an exponential distribution.
(class template)
Produces real values on an gamma distribution.
(class template)
Produces real values on a Weibull distribution.
(class template)
Produces real values on an extreme value distribution.
(class template)
Normal distributions
Produces real values on a standard normal (Gaussian) distribution.
(class template)
Produces real values on a lognormal distribution.
(class template)
Produces real values on a chi-squared distribution.
(class template)
Produces real values on a Cauchy distribution.
(class template)
Produces real values on a Fisher's F-distribution.
(class template)
Produces real values on a Student's t-distribution.
(class template)
Sampling distributions
Produces random integers on a discrete distribution.
(class template)
Produces real values distributed on constant subintervals.
(class template)
Produces real values distributed on defined subintervals.
(class template)

Predefined seed sequence generators

Defined in header <random>
(C++11)
general-purpose bias-eliminating scrambled seed sequence generator
(class)

C library

Template:cpp/numeric/random/dcl list randTemplate:cpp/numeric/random/dcl list srand
Defined in header <cstdlib>
maximum possible value generated by Template:rlf
(macro constant)