STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx > Class Template Reference
Inheritance diagram for mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >:
_Circ_buf< _Ty, _Nx > mersenne_twister_engine< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Dx, _Sx, _Bx, _Tx, _Cx, _Lx, _Fx >

Public Types

typedef mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx > _Myt
 
typedef _Ty result_type
 

Public Member Functions

 mersenne_twister (_Ty _X0=default_seed, _Ty _Dxarg=_WMSK, _Ty _Fxarg=(_Ty) 1812433253)
 
template<class _Gen , class = typename _Enable_if_seed_seq<_Gen, _Myt>::type>
 mersenne_twister (_Gen &_Gx)
 
void seed (_Ty _X0=default_seed, _Ty _Fx=(_Ty) 1812433253)
 
template<class _Gen , class = typename _Enable_if_seed_seq<_Gen, _Myt>::type>
void seed (_Gen &_Gx, bool=false)
 
template<class _Elem , class _S_Traits >
basic_ostream< _Elem, _S_Traits > & _Write (basic_ostream< _Elem, _S_Traits > &_Ostr) const
 
result_type() min () const
 
result_type() max () const
 
result_type operator() ()
 
void discard (unsigned long long _Nskip)
 
- Public Member Functions inherited from _Circ_buf< _Ty, _Nx >
_Ty _At (int _Ix) const
 
bool _Equals (const _Circ_buf &_Right) const
 
unsigned int _Base (int _Ix=0) const
 

Static Public Attributes

static constexpr int word_size = _Wx
 
static constexpr int state_size = _Nx
 
static constexpr int shift_size = _Mx
 
static constexpr int mask_bits = _Rx
 
static constexpr _Ty parameter_a = _Px
 
static constexpr int output_u = _Ux
 
static constexpr int output_s = _Sx
 
static constexpr _Ty output_b = _Bx
 
static constexpr int output_t = _Tx
 
static constexpr _Ty output_c = _Cx
 
static constexpr int output_l = _Lx
 
static constexpr _Ty default_seed = 5489U
 

Protected Member Functions

 _Post_satisfies_ (this->_Idx==0) void _Refill_lower()
 
void _Refill_upper ()
 

Protected Attributes

_Ty _Dxval
 

Static Protected Attributes

static constexpr _Ty _WMSK = ~((~_Ty(0) << (_Wx - 1)) << 1)
 
static constexpr _Ty _HMSK = (_WMSK << _Rx) & _WMSK
 
static constexpr _Ty _LMSK = ~_HMSK & _WMSK
 

Additional Inherited Members

- Public Attributes inherited from _Circ_buf< _Ty, _Nx >
unsigned int _Idx
 
_Ty _Ax [2 *_Nw]
 

Member Typedef Documentation

template<class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
typedef mersenne_twister<_Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx> mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::_Myt
template<class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
typedef _Ty mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::result_type

Constructor & Destructor Documentation

template<class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::mersenne_twister ( _Ty  _X0 = default_seed,
_Ty  _Dxarg = _WMSK,
_Ty  _Fxarg = (_Ty)1812433253 
)
inlineexplicit
1324  : _Dxval(_Dxarg)
1325  { // construct with specified seed
1326  seed(_X0, _Fxarg);
1327  }
void seed(_Ty _X0=default_seed, _Ty _Fx=(_Ty) 1812433253)
Definition: random:1337
_Ty _Dxval
Definition: random:1438
template<class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
template<class _Gen , class = typename _Enable_if_seed_seq<_Gen, _Myt>::type>
mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::mersenne_twister ( _Gen &  _Gx)
inlineexplicit
1332  : _Dxval(_WMSK)
1333  { // construct with seed values from generator
1334  seed(_Gx);
1335  }
void seed(_Ty _X0=default_seed, _Ty _Fx=(_Ty) 1812433253)
Definition: random:1337
static constexpr _Ty _WMSK
Definition: random:1440
_Ty _Dxval
Definition: random:1438

Member Function Documentation

template<class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::_Post_satisfies_ ( this->  _Idx = = 0)
inlineprotected
1402  { // compute values for the lower half of the history array
1403  int _Ix;
1404  for (_Ix = 0; _Ix < _Nx - _Mx; ++_Ix)
1405  { // fill in lower region
1406  _Ty _Tmp = (this->_Ax[_Ix + _Nx] & _HMSK)
1407  | (this->_Ax[_Ix + _Nx + 1] & _LMSK);
1408  this->_Ax[_Ix] = (_Tmp >> 1)
1409  ^ (_Tmp & 1 ? _Px : 0) ^ this->_Ax[_Ix + _Nx + _Mx];
1410  }
1411 
1412  for (; _Ix < _Nx - 1; ++_Ix)
1413  { // fill in upper region (avoids modulus operation)
1414  _Ty _Tmp = (this->_Ax[_Ix +_Nx] & _HMSK)
1415  | (this->_Ax[_Ix + _Nx + 1] & _LMSK);
1416  this->_Ax[_Ix] = (_Tmp >> 1)
1417  ^ (_Tmp & 1 ? _Px : 0) ^ this->_Ax[_Ix - _Nx + _Mx];
1418  }
1419 
1420  _Ty _Tmp = (this->_Ax[_Ix + _Nx] & _HMSK) | (this->_Ax[0] & _LMSK);
1421  this->_Ax[_Ix] = (_Tmp >> 1)
1422  ^ (_Tmp & 1 ? _Px : 0) ^ this->_Ax[_Mx - 1];
1423  this->_Idx = 0;
1424  }
unsigned int _Idx
Definition: random:754
_Ty _Ax[2 *_Nw]
Definition: random:755
static constexpr _Ty _LMSK
Definition: random:1442
static constexpr _Ty _HMSK
Definition: random:1441
template<class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
void mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::_Refill_upper ( )
inlineprotected
1427  { // compute values for the upper half of the history array
1428  int _Ix;
1429  for (_Ix = _Nx; _Ix < 2 * _Nx; ++_Ix)
1430  { // fill in values
1431  _Ty _Tmp = (this->_Ax[_Ix - _Nx] & _HMSK)
1432  | (this->_Ax[_Ix - _Nx + 1] & _LMSK);
1433  this->_Ax[_Ix] = (_Tmp >> 1)
1434  ^ (_Tmp & 1 ? _Px : 0) ^ this->_Ax[_Ix - _Nx + _Mx];
1435  }
1436  }
_Ty _Ax[2 *_Nw]
Definition: random:755
static constexpr _Ty _LMSK
Definition: random:1442
static constexpr _Ty _HMSK
Definition: random:1441
template<class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
template<class _Elem , class _S_Traits >
basic_ostream<_Elem, _S_Traits>& mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::_Write ( basic_ostream< _Elem, _S_Traits > &  _Ostr) const
inline
1360  { // write state to _Ostr
1361  for (int _Ix = 0; _Ix < _Nx; ++_Ix)
1362  _Ostr << this->_At(_Ix) << ' ';
1363  return (_Ostr);
1364  }
_Ty _At(int _Ix) const
Definition: random:700
template<class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
void mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::discard ( unsigned long long  _Nskip)
inline
1392  { // discard _Nskip elements
1393  for (; 0 < _Nskip; --_Nskip)
1394  (*this)();
1395  }
template<class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
result_type() mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::max ( ) const
inline
1372  { // return maximum possible generated value
1373  return (_WMSK);
1374  }
static constexpr _Ty _WMSK
Definition: random:1440
template<class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
result_type() mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::min ( ) const
inline
1367  { // return minimum possible generated value
1368  return (0);
1369  }
template<class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
result_type mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::operator() ( )
inline
1377  { // return next value
1378  if (this->_Idx == _Nx)
1379  _Refill_upper();
1380  else if (2 * _Nx <= this->_Idx)
1381  _Refill_lower();
1382 
1383  _Ty _Res = this->_Ax[this->_Idx++] & _WMSK;
1384  _Res ^= (_Res >> _Ux) & _Dxval;
1385  _Res ^= (_Res << _Sx) & _Bx;
1386  _Res ^= (_Res << _Tx) & _Cx;
1387  _Res ^= (_Res & _WMSK) >> _Lx;
1388  return (_Res);
1389  }
void _Refill_upper()
Definition: random:1426
unsigned int _Idx
Definition: random:754
_Ty _Ax[2 *_Nw]
Definition: random:755
static constexpr _Ty _WMSK
Definition: random:1440
_Ty _Dxval
Definition: random:1438
template<class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
void mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::seed ( _Ty  _X0 = default_seed,
_Ty  _Fx = (_Ty)1812433253 
)
inline
1339  { // set initial values from specified value
1340  _Ty _Prev = this->_Ax[0] = _X0 & _WMSK;
1341  for (int _Ix = 1; _Ix < _Nx; ++_Ix)
1342  _Prev = this->_Ax[_Ix] =
1343  (_Ix + _Fx * (_Prev ^ (_Prev >> (_Wx - 2)))) & _WMSK;
1344  this->_Idx = _Nx;
1345  }
unsigned int _Idx
Definition: random:754
_Ty _Ax[2 *_Nw]
Definition: random:755
static constexpr _Ty _WMSK
Definition: random:1440
template<class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
template<class _Gen , class = typename _Enable_if_seed_seq<_Gen, _Myt>::type>
void mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::seed ( _Gen &  _Gx,
bool  = false 
)
inline
1350  { // set initial values from range
1351  for (int _Ix = 0; _Ix < _Nx; ++_Ix)
1352  this->_Ax[_Ix] = _Gx() & _WMSK;
1353  this->_Idx = _Nx;
1354  }
unsigned int _Idx
Definition: random:754
_Ty _Ax[2 *_Nw]
Definition: random:755
static constexpr _Ty _WMSK
Definition: random:1440

Member Data Documentation

template<class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
_Ty mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::_Dxval
protected
template<class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
constexpr _Ty mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::_HMSK = (_WMSK << _Rx) & _WMSK
staticprotected
template<class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
constexpr _Ty mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::_LMSK = ~_HMSK & _WMSK
staticprotected
template<class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
constexpr _Ty mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::_WMSK = ~((~_Ty(0) << (_Wx - 1)) << 1)
staticprotected
template<class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
constexpr _Ty mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::default_seed = 5489U
static
template<class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
constexpr int mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::mask_bits = _Rx
static
template<class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
constexpr _Ty mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::output_b = _Bx
static
template<class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
constexpr _Ty mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::output_c = _Cx
static
template<class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
constexpr int mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::output_l = _Lx
static
template<class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
constexpr int mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::output_s = _Sx
static
template<class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
constexpr int mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::output_t = _Tx
static
template<class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
constexpr int mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::output_u = _Ux
static
template<class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
constexpr _Ty mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::parameter_a = _Px
static
template<class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
constexpr int mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::shift_size = _Mx
static
template<class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
constexpr int mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::state_size = _Nx
static
template<class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
constexpr int mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::word_size = _Wx
static

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