Boost  v1.57.0
doxygen for www.boost.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
boost::random::linear_congruential_engine< IntType, a, c, m > Class Template Reference

Instantiations of class template linear_congruential_engine model a . More...

#include <linear_congruential.hpp>

Public Types

typedef IntType result_type
 

Public Member Functions

 BOOST_STATIC_CONSTANT (bool, has_fixed_range=false)
 
 BOOST_STATIC_CONSTANT (IntType, multiplier=a)
 
 BOOST_STATIC_CONSTANT (IntType, increment=c)
 
 BOOST_STATIC_CONSTANT (IntType, modulus=m)
 
 BOOST_STATIC_CONSTANT (IntType, default_seed=1)
 
 BOOST_STATIC_ASSERT (std::numeric_limits< IntType >::is_integer)
 
 BOOST_STATIC_ASSERT (m==0||a< m)
 
 BOOST_STATIC_ASSERT (m==0||c< m)
 
 linear_congruential_engine ()
 Constructs a linear_congruential_engine, using the default seed. More...
 
 BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR (linear_congruential_engine, IntType, x0)
 Constructs a linear_congruential_engine, seeding it with x0. More...
 
 BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR (linear_congruential_engine, SeedSeq, seq)
 Constructs a linear_congruential_engine, seeding it with values produced by a call to seq.generate(). More...
 
template<class It >
 linear_congruential_engine (It &first, It last)
 Constructs a linear_congruential_engine and seeds it with values taken from the itrator range [first, last) and adjusts first to point to the element after the last one used. More...
 
void seed ()
 Calls seed(default_seed) More...
 
 BOOST_RANDOM_DETAIL_ARITHMETIC_SEED (linear_congruential_engine, IntType, x0)
 If c mod m is zero and x0 mod m is zero, changes the current value of the generator to 1. More...
 
 BOOST_RANDOM_DETAIL_SEED_SEQ_SEED (linear_congruential_engine, SeedSeq, seq)
 Seeds a linear_congruential_engine using values from a SeedSeq. More...
 
template<class It >
void seed (It &first, It last)
 seeds a linear_congruential_engine with values taken from the itrator range [first, last) and adjusts first to point to the element after the last one used. More...
 
IntType operator() ()
 Returns the next value of the linear_congruential_engine. More...
 
template<class Iter >
void generate (Iter first, Iter last)
 Fills a range with random values. More...
 
void discard (boost::uintmax_t z)
 Advances the state of the generator by z. More...
 

Static Public Member Functions

static result_type min BOOST_PREVENT_MACRO_SUBSTITUTION ()
 Returns the smallest value that the linear_congruential_engine can produce. More...
 
static result_type max BOOST_PREVENT_MACRO_SUBSTITUTION ()
 Returns the largest value that the linear_congruential_engine can produce. More...
 

Friends

bool operator== (const linear_congruential_engine &x, const linear_congruential_engine &y)
 
bool operator!= (const linear_congruential_engine &x, const linear_congruential_engine &y)
 
template<class CharT , class Traits >
std::basic_ostream< CharT,
Traits > & 
operator<< (std::basic_ostream< CharT, Traits > &os, const linear_congruential_engine &lcg)
 Writes a linear_congruential_engine to a std::ostream. More...
 
template<class CharT , class Traits >
std::basic_istream< CharT,
Traits > & 
operator>> (std::basic_istream< CharT, Traits > &is, linear_congruential_engine &lcg)
 Reads a linear_congruential_engine from a std::istream. More...
 

Detailed Description

template<class IntType, IntType a, IntType c, IntType m>
class boost::random::linear_congruential_engine< IntType, a, c, m >

Instantiations of class template linear_congruential_engine model a .

Linear congruential pseudo-random number generators are described in:

"Mathematical methods in large-scale computing units", D. H. Lehmer, Proc. 2nd Symposium on Large-Scale Digital Calculating Machines, Harvard University Press, 1951, pp. 141-146

Let x(n) denote the sequence of numbers returned by some pseudo-random number generator. Then for the linear congruential generator, x(n+1) := (a * x(n) + c) mod m. Parameters for the generator are x(0), a, c, m. The template parameter IntType shall denote an integral type. It must be large enough to hold values a, c, and m. The template parameters a and c must be smaller than m.

Note: The quality of the generator crucially depends on the choice of the parameters. User code should use one of the sensibly parameterized generators such as minstd_rand instead.

Member Typedef Documentation

template<class IntType , IntType a, IntType c, IntType m>
typedef IntType boost::random::linear_congruential_engine< IntType, a, c, m >::result_type

Constructor & Destructor Documentation

template<class IntType , IntType a, IntType c, IntType m>
boost::random::linear_congruential_engine< IntType, a, c, m >::linear_congruential_engine ( )
inline
template<class IntType , IntType a, IntType c, IntType m>
template<class It >
boost::random::linear_congruential_engine< IntType, a, c, m >::linear_congruential_engine ( It &  first,
It  last 
)
inline

Constructs a linear_congruential_engine and seeds it with values taken from the itrator range [first, last) and adjusts first to point to the element after the last one used.

If there are not enough elements, throws std::invalid_argument.

first and last must be input iterators.

References boost::random::linear_congruential_engine< IntType, a, c, m >::seed().

Member Function Documentation

template<class IntType , IntType a, IntType c, IntType m>
static result_type min boost::random::linear_congruential_engine< IntType, a, c, m >::BOOST_PREVENT_MACRO_SUBSTITUTION ( )
inlinestatic

Returns the smallest value that the linear_congruential_engine can produce.

References boost::multiprecision::backends::c.

template<class IntType , IntType a, IntType c, IntType m>
static result_type max boost::random::linear_congruential_engine< IntType, a, c, m >::BOOST_PREVENT_MACRO_SUBSTITUTION ( )
inlinestatic

Returns the largest value that the linear_congruential_engine can produce.

template<class IntType , IntType a, IntType c, IntType m>
boost::random::linear_congruential_engine< IntType, a, c, m >::BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR ( linear_congruential_engine< IntType, a, c, m >  ,
IntType  ,
x0   
)
inline
template<class IntType , IntType a, IntType c, IntType m>
boost::random::linear_congruential_engine< IntType, a, c, m >::BOOST_RANDOM_DETAIL_ARITHMETIC_SEED ( linear_congruential_engine< IntType, a, c, m >  ,
IntType  ,
x0   
)
inline

If c mod m is zero and x0 mod m is zero, changes the current value of the generator to 1.

Otherwise, changes it to x0 mod m. If c is zero, distinct seeds in the range [1,m) will leave the generator in distinct states. If c is not zero, the range is [0,m).

References BOOST_ASSERT, boost::numeric::ublas::increment(), boost::accumulators::extract::max, and boost::accumulators::extract::min.

template<class IntType , IntType a, IntType c, IntType m>
boost::random::linear_congruential_engine< IntType, a, c, m >::BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR ( linear_congruential_engine< IntType, a, c, m >  ,
SeedSeq  ,
seq   
)
inline

Constructs a linear_congruential_engine, seeding it with values produced by a call to seq.generate().

References boost::random::linear_congruential_engine< IntType, a, c, m >::seed().

template<class IntType , IntType a, IntType c, IntType m>
boost::random::linear_congruential_engine< IntType, a, c, m >::BOOST_RANDOM_DETAIL_SEED_SEQ_SEED ( linear_congruential_engine< IntType, a, c, m >  ,
SeedSeq  ,
seq   
)
inline
template<class IntType , IntType a, IntType c, IntType m>
boost::random::linear_congruential_engine< IntType, a, c, m >::BOOST_STATIC_ASSERT ( std::numeric_limits< IntType >::is_integer  )
template<class IntType , IntType a, IntType c, IntType m>
boost::random::linear_congruential_engine< IntType, a, c, m >::BOOST_STATIC_ASSERT ( )
template<class IntType , IntType a, IntType c, IntType m>
boost::random::linear_congruential_engine< IntType, a, c, m >::BOOST_STATIC_ASSERT ( )
template<class IntType , IntType a, IntType c, IntType m>
boost::random::linear_congruential_engine< IntType, a, c, m >::BOOST_STATIC_CONSTANT ( bool  ,
has_fixed_range  = false 
)
template<class IntType , IntType a, IntType c, IntType m>
boost::random::linear_congruential_engine< IntType, a, c, m >::BOOST_STATIC_CONSTANT ( IntType  ,
multiplier  = a 
)
template<class IntType , IntType a, IntType c, IntType m>
boost::random::linear_congruential_engine< IntType, a, c, m >::BOOST_STATIC_CONSTANT ( IntType  ,
increment  = c 
)
template<class IntType , IntType a, IntType c, IntType m>
boost::random::linear_congruential_engine< IntType, a, c, m >::BOOST_STATIC_CONSTANT ( IntType  ,
modulus  = m 
)
template<class IntType , IntType a, IntType c, IntType m>
boost::random::linear_congruential_engine< IntType, a, c, m >::BOOST_STATIC_CONSTANT ( IntType  ,
default_seed  = 1 
)
template<class IntType , IntType a, IntType c, IntType m>
void boost::random::linear_congruential_engine< IntType, a, c, m >::discard ( boost::uintmax_t  z)
inline

Advances the state of the generator by z.

References boost::a, boost::icl::add(), boost::multiprecision::backends::c, boost::iostreams::grep::invert, and pow().

template<class IntType , IntType a, IntType c, IntType m>
template<class Iter >
void boost::random::linear_congruential_engine< IntType, a, c, m >::generate ( Iter  first,
Iter  last 
)
inline

Fills a range with random values.

template<class IntType , IntType a, IntType c, IntType m>
IntType boost::random::linear_congruential_engine< IntType, a, c, m >::operator() ( )
inline

Returns the next value of the linear_congruential_engine.

References boost::a, and boost::multiprecision::backends::c.

template<class IntType , IntType a, IntType c, IntType m>
template<class It >
void boost::random::linear_congruential_engine< IntType, a, c, m >::seed ( It &  first,
It  last 
)
inline

seeds a linear_congruential_engine with values taken from the itrator range [first, last) and adjusts first to point to the element after the last one used.

If there are not enough elements, throws std::invalid_argument.

first and last must be input iterators.

References boost::random::linear_congruential_engine< IntType, a, c, m >::seed().

Friends And Related Function Documentation

template<class IntType , IntType a, IntType c, IntType m>
bool operator!= ( const linear_congruential_engine< IntType, a, c, m > &  x,
const linear_congruential_engine< IntType, a, c, m > &  y 
)
friend
template<class IntType , IntType a, IntType c, IntType m>
template<class CharT , class Traits >
std::basic_ostream<CharT,Traits>& operator<< ( std::basic_ostream< CharT, Traits > &  os,
const linear_congruential_engine< IntType, a, c, m > &  lcg 
)
friend

Writes a linear_congruential_engine to a std::ostream.

template<class IntType , IntType a, IntType c, IntType m>
bool operator== ( const linear_congruential_engine< IntType, a, c, m > &  x,
const linear_congruential_engine< IntType, a, c, m > &  y 
)
friend
template<class IntType , IntType a, IntType c, IntType m>
template<class CharT , class Traits >
std::basic_istream<CharT,Traits>& operator>> ( std::basic_istream< CharT, Traits > &  is,
linear_congruential_engine< IntType, a, c, m > &  lcg 
)
friend

Reads a linear_congruential_engine from a std::istream.


The documentation for this class was generated from the following file: