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 (unsigned long _X0=default_seed, _Ty _Dxarg=_WMSK, _Ty _Fxarg=(_Ty) 1812433253)
 
 mersenne_twister (const mersenne_twister &_Right)
 
 mersenne_twister (mersenne_twister &_Right)
 
template<class _Gen >
 mersenne_twister (_Gen &_Gx)
 
void seed (unsigned long _X0=default_seed, _Ty _Fx=(_Ty) 1812433253)
 
template<class _Gen >
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 const int word_size = _Wx
 
static const int state_size = _Nx
 
static const int shift_size = _Mx
 
static const int mask_bits = _Rx
 
static const _Ty parameter_a = _Px
 
static const int output_u = _Ux
 
static const int output_s = _Sx
 
static const _Ty output_b = _Bx
 
static const int output_t = _Tx
 
static const _Ty output_c = _Cx
 
static const int output_l = _Lx
 
static const _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 const _Ty _WMSK = ~((~_Ty(0) << (_Wx - 1)) << 1)
 
static const _Ty _HMSK = (_WMSK << _Rx) & _WMSK
 
static const _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 ( unsigned long  _X0 = default_seed,
_Ty  _Dxarg = _WMSK,
_Ty  _Fxarg = (_Ty)1812433253 
)
inlineexplicit
1354  : _Dxval(_Dxarg)
1355  { // construct with specified seed
1356  seed(_X0, _Fxarg);
1357  }
void seed(unsigned long _X0=default_seed, _Ty _Fx=(_Ty) 1812433253)
Definition: random:1376
_Ty _Dxval
Definition: random:1476
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 ( const mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx > &  _Right)
inline
1360  { // construct by copying
1361  *this = _Right;
1362  }
const _Ty & _Right
Definition: algorithm:4087
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 ( mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx > &  _Right)
inline
1365  { // construct by copying
1366  *this = _Right;
1367  }
const _Ty & _Right
Definition: algorithm:4087
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 >
mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::mersenne_twister ( _Gen &  _Gx)
inlineexplicit
1371  : _Dxval(_WMSK)
1372  { // construct with seed values from generator
1373  seed(_Gx);
1374  }
void seed(unsigned long _X0=default_seed, _Ty _Fx=(_Ty) 1812433253)
Definition: random:1376
static const _Ty _WMSK
Definition: random:1478
_Ty _Dxval
Definition: random:1476

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
1440  { // compute values for the lower half of the history array
1441  int _Ix;
1442  for (_Ix = 0; _Ix < _Nx - _Mx; ++_Ix)
1443  { // fill in lower region
1444  _Ty _Tmp = (this->_Ax[_Ix + _Nx] & _HMSK)
1445  | (this->_Ax[_Ix + _Nx + 1] & _LMSK);
1446  this->_Ax[_Ix] = (_Tmp >> 1)
1447  ^ (_Tmp & 1 ? _Px : 0) ^ this->_Ax[_Ix + _Nx + _Mx];
1448  }
1449 
1450  for (; _Ix < _Nx - 1; ++_Ix)
1451  { // fill in upper region (avoids modulus operation)
1452  _Ty _Tmp = (this->_Ax[_Ix +_Nx] & _HMSK)
1453  | (this->_Ax[_Ix + _Nx + 1] & _LMSK);
1454  this->_Ax[_Ix] = (_Tmp >> 1)
1455  ^ (_Tmp & 1 ? _Px : 0) ^ this->_Ax[_Ix - _Nx + _Mx];
1456  }
1457 
1458  _Ty _Tmp = (this->_Ax[_Ix + _Nx] & _HMSK) | (this->_Ax[0] & _LMSK);
1459  this->_Ax[_Ix] = (_Tmp >> 1)
1460  ^ (_Tmp & 1 ? _Px : 0) ^ this->_Ax[_Mx - 1];
1461  this->_Idx = 0;
1462  }
unsigned int _Idx
Definition: random:777
_Ty _Ax[2 *_Nw]
Definition: random:778
static const _Ty _HMSK
Definition: random:1479
static const _Ty _LMSK
Definition: random:1480
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
1465  { // compute values for the upper half of the history array
1466  int _Ix;
1467  for (_Ix = _Nx; _Ix < 2 * _Nx; ++_Ix)
1468  { // fill in values
1469  _Ty _Tmp = (this->_Ax[_Ix - _Nx] & _HMSK)
1470  | (this->_Ax[_Ix - _Nx + 1] & _LMSK);
1471  this->_Ax[_Ix] = (_Tmp >> 1)
1472  ^ (_Tmp & 1 ? _Px : 0) ^ this->_Ax[_Ix - _Nx + _Mx];
1473  }
1474  }
_Ty _Ax[2 *_Nw]
Definition: random:778
static const _Ty _HMSK
Definition: random:1479
static const _Ty _LMSK
Definition: random:1480
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
1398  { // write state to _Ostr
1399  for (int _Ix = 0; _Ix < _Nx; ++_Ix)
1400  _Ostr << this->_At(_Ix) << ' ';
1401  return (_Ostr);
1402  }
_Ty _At(int _Ix) const
Definition: random:723
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
1430  { // discard _Nskip elements
1431  for (; 0 < _Nskip; --_Nskip)
1432  (*this)();
1433  }
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
1410  { // return maximum possible generated value
1411  return (_WMSK);
1412  }
static const _Ty _WMSK
Definition: random:1478
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
1405  { // return minimum possible generated value
1406  return (0);
1407  }
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
1415  { // return next value
1416  if (this->_Idx == _Nx)
1417  _Refill_upper();
1418  else if (2 * _Nx <= this->_Idx)
1419  _Refill_lower();
1420 
1421  _Ty _Res = this->_Ax[this->_Idx++] & _WMSK;
1422  _Res ^= (_Res >> _Ux) & _Dxval;
1423  _Res ^= (_Res << _Sx) & _Bx;
1424  _Res ^= (_Res << _Tx) & _Cx;
1425  _Res ^= (_Res & _WMSK) >> _Lx;
1426  return (_Res);
1427  }
void _Refill_upper()
Definition: random:1464
unsigned int _Idx
Definition: random:777
_Ty _Ax[2 *_Nw]
Definition: random:778
static const _Ty _WMSK
Definition: random:1478
_Ty _Dxval
Definition: random:1476
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 ( unsigned long  _X0 = default_seed,
_Ty  _Fx = (_Ty)1812433253 
)
inline
1378  { // set initial values from specified value
1379  _Ty _Prev = this->_Ax[0] = _X0 & _WMSK;
1380  for (int _Ix = 1; _Ix < _Nx; ++_Ix)
1381  _Prev = this->_Ax[_Ix] =
1382  (_Ix + _Fx * (_Prev ^ (_Prev >> (_Wx - 2)))) & _WMSK;
1383  this->_Idx = _Nx;
1384  }
unsigned int _Idx
Definition: random:777
_Ty _Ax[2 *_Nw]
Definition: random:778
static const _Ty _WMSK
Definition: random:1478
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 >
void mersenne_twister< _Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx >::seed ( _Gen &  _Gx,
bool  = false 
)
inline
1388  { // set initial values from range
1389  for (int _Ix = 0; _Ix < _Nx; ++_Ix)
1390  this->_Ax[_Ix] = _Gx() & _WMSK;
1391  this->_Idx = _Nx;
1392  }
unsigned int _Idx
Definition: random:777
_Ty _Ax[2 *_Nw]
Definition: random:778
static const _Ty _WMSK
Definition: random:1478

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>
const _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>
const _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>
const _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>
const _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>
const 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>
const _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>
const _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>
const 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>
const 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>
const 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>
const 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>
const _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>
const 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>
const 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>
const 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: