# Standard library header <random>

From cppreference.com
< cpp‎ | header

This header is part of the pseudo-random number generation library.

##### Uniform random bit generator requirements

UniformRandomBitGenerator (C++20) | specifies that a type qualifies as a uniform random bit generator (concept)

##### Random number engines

linear_congruential_engine (C++11) | implements linear congruential algorithm (class template)
mersenne_twister_engine (C++11) | implements Mersenne twister algorithm (class template)
subtract_with_carry_engine (C++11) | implements a subtract-with-carry ( lagged Fibonacci) algorithm (class template)

##### Random number engine adaptors

discard_block_engine (C++11) | discards some output of a random number engine (class template)
independent_bits_engine (C++11) | packs the output of a random number engine into blocks of a specified number of bits (class template)
shuffle_order_engine (C++11) | delivers the output of a random number engine in a different order (class template)

##### Predefined generators

`minstd_rand0`(C++11) | std::linear_congruential_engine<std::uint_fast32_t, 16807, 0, 2147483647> Discovered in 1969 by Lewis, Goodman and Miller, adopted as "Minimal standard" in 1988 by Park and Miller
`minstd_rand`(C++11) | std::linear_congruential_engine<std::uint_fast32_t, 48271, 0, 2147483647> Newer "Minimum standard", recommended by Park, Miller, and Stockmeyer in 1993
`mt19937`(C++11) | std::mersenne_twister_engine<std::uint_fast32_t, 32, 624, 397, 31, 0x9908b0df, 11, 0xffffffff, 7, 0x9d2c5680, 15, 0xefc60000, 18, 1812433253> 32-bit Mersenne Twister by Matsumoto and Nishimura, 1998
`mt19937_64`(C++11) | std::mersenne_twister_engine<std::uint_fast64_t, 64, 312, 156, 31, 0xb5026f5aa96619e9, 29, 0x5555555555555555, 17, 0x71d67fffeda60000, 37, 0xfff7eee000000000, 43, 6364136223846793005> 64-bit Mersenne Twister by Matsumoto and Nishimura, 2000
`ranlux24_base`(C++11) | std::subtract_with_carry_engine<std::uint_fast32_t, 24, 10, 24>
`ranlux48_base`(C++11) | std::subtract_with_carry_engine<std::uint_fast64_t, 48, 5, 12>
`ranlux24`(C++11) | std::discard_block_engine<std::ranlux24_base, 223, 23> 24-bit RANLUX generator by Martin Lüscher and Fred James, 1994
`ranlux48`(C++11) | std::discard_block_engine<std::ranlux48_base, 389, 11> 48-bit RANLUX generator by Martin Lüscher and Fred James, 1994
`knuth_b`(C++11) | std::shuffle_order_engine<std::minstd_rand0, 256>
`default_random_engine` | implementation-defined

##### Non-deterministic random numbers

random_device (C++11) | non-deterministic random number generator using hardware entropy source (class)

##### Uniform distributions

uniform_int_distribution (C++11) | produces integer values evenly distributed across a range (class template)
uniform_real_distribution (C++11) | produces real values evenly distributed across a range (class template)

##### Bernoulli distributions

bernoulli_distribution (C++11) | produces bool values on a Bernoulli distribution. (class)
binomial_distribution (C++11) | produces integer values on a binomial distribution. (class template)
negative_binomial_distribution (C++11) | produces integer values on a negative binomial distribution. (class template)
geometric_distribution (C++11) | produces integer values on a geometric distribution. (class template)

##### Poisson distributions

poisson_distribution (C++11) | produces integer values on a poisson distribution. (class template)
exponential_distribution (C++11) | produces real values on an exponential distribution. (class template)
gamma_distribution (C++11) | produces real values on an gamma distribution. (class template)
weibull_distribution (C++11) | produces real values on a Weibull distribution. (class template)
extreme_value_distribution (C++11) | produces real values on an extreme value distribution. (class template)

##### Normal distributions

normal_distribution (C++11) | produces real values on a standard normal (Gaussian) distribution. (class template)
lognormal_distribution (C++11) | produces real values on a lognormal distribution. (class template)
chi_squared_distribution (C++11) | produces real values on a chi-squared distribution. (class template)
cauchy_distribution (C++11) | produces real values on a Cauchy distribution. (class template)
fisher_f_distribution (C++11) | produces real values on a Fisher's F-distribution. (class template)
student_t_distribution (C++11) | produces real values on a Student's t-distribution. (class template)

##### Sampling distributions

discrete_distribution (C++11) | produces random integers on a discrete distribution. (class template)
piecewise_constant_distribution (C++11) | produces real values distributed on constant subintervals. (class template)
piecewise_linear_distribution (C++11) | produces real values distributed on defined subintervals. (class template)

##### Utilities

generate_canonical (C++11) | evenly distributes real values of given precision across [0, 1) (function template)
seed_seq (C++11) | general-purpose bias-eliminating scrambled seed sequence generator (class)

### Synopsis

    #include <initializer_list>
    namespace std {
      // uniform random bit generator requirements
      template<class G>
        concept UniformRandomBitGenerator = /*see below*/;

      // class template linear_congruential_engine
      template<class UIntType, UIntType a, UIntType c, UIntType m>
      class linear_congruential_engine;
      // class template mersenne_twister_engine
      template<class UIntType, size_t w, size_t n, size_t m, size_t r,
               UIntType a, size_t u, UIntType d, size_t s,
               UIntType b, size_t t, UIntType c, size_t l, UIntType f>
      class mersenne_twister_engine;
      // class template subtract_with_carry_engine
      template<class UIntType, size_t w, size_t s, size_t r>
      class subtract_with_carry_engine;
      // class template discard_block_engine
      template<class Engine, size_t p, size_t r>
      class discard_block_engine;
      // class template independent_bits_engine
      template<class Engine, size_t w, class UIntType>
      class independent_bits_engine;
      // class template shuffle_order_engine
      template<class Engine, size_t k>
      class shuffle_order_engine;
      // engines and engine adaptors with predefined parameters
      using minstd_rand0 = /*see description*/ ;
      using minstd_rand = /*see description*/ ;
      using mt19937 = /*see description*/ ;
      using mt19937_64 = /*see description*/ ;
      using ranlux24_base = /*see description*/ ;
      using ranlux48_base = /*see description*/ ;
      using ranlux24 = /*see description*/ ;
      using ranlux48 = /*see description*/ ;
      using knuth_b = /*see description*/ ;
      using default_random_engine = /*see description*/ ;
      // class random_device
      class random_device;

      // class seed_seq
      class seed_seq;
      // function template generate_canonical
      template<class RealType, size_t bits, class URBG>
      RealType generate_canonical(URBG& g);
      // class template uniform_int_distribution
      template<class IntType = int>
      class uniform_int_distribution;
      // class template uniform_real_distribution
      template<class RealType = double>
      class uniform_real_distribution;
      // class bernoulli_distribution
      class bernoulli_distribution;
      // class template binomial_distribution
      template<class IntType = int>
      class binomial_distribution;
      // class template geometric_distribution
      template<class IntType = int>
      class geometric_distribution;
      // class template negative_binomial_distribution
      template<class IntType = int>
      class negative_binomial_distribution;
      // class template poisson_distribution
      template<class IntType = int>
      class poisson_distribution;
      // class template exponential_distribution
      template<class RealType = double>
      class exponential_distribution;
      // class template gamma_distribution
      template<class RealType = double>
      class gamma_distribution;
      // class template weibull_distribution
      template<class RealType = double>
      class weibull_distribution;
      // class template extreme_value_distribution
      template<class RealType = double>
      class extreme_value_distribution;
      // class template normal_distribution
      template<class RealType = double>
      class normal_distribution;
      // class template lognormal_distribution
      template<class RealType = double>
      class lognormal_distribution;
      // class template chi_squared_distribution
      template<class RealType = double>
      class chi_squared_distribution;
      // class template cauchy_distribution
      template<class RealType = double>
      class cauchy_distribution;
      // class template fisher_f_distribution
      template<class RealType = double>
      class fisher_f_distribution;
      // class template student_t_distribution
      template<class RealType = double>
      class student_t_distribution;
      // class template discrete_distribution
      template<class IntType = int>
      class discrete_distribution;
      // class template piecewise_constant_distribution
      template<class RealType = double>
      class piecewise_constant_distribution;
      // class template piecewise_linear_distribution
      template<class RealType = double>
      class piecewise_linear_distribution;
    }

Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/header/random&oldid=105658"