RandomLib  1.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
Namespaces | Macros
Random.cpp File Reference

Implementation code for RandomLib. More...

#include <RandomLib/Random.hpp>
#include <fstream>
#include <ctime>
#include <sstream>
#include <iomanip>
#include <sys/time.h>
#include <unistd.h>

Go to the source code of this file.

Namespaces

 RandomLib
 Namespace for RandomLib.
 

Macros

#define RANDOMLIB_RANDOM_CPP   1
 
#define RANDOMLIB_BUILDING_LIBRARY   1
 
#define RANDOMLIB_WINDOWS   0
 
#define MT19937_STEP(I, J, K)
 
#define MT19937_REVSTEP(I, J, K)
 
#define SFMT19937_STEP32(I, J)
 
#define SFMT19937_REVSTEP32(I, J, K, L)
 
#define SFMT19937_STEP64(I, J)
 
#define SFMT19937_REVSTEP64(I, J, K, L)
 

Detailed Description

Implementation code for RandomLib.

Copyright (c) Charles Karney (2006-2011) charl.nosp@m.es@k.nosp@m.arney.nosp@m..com and licensed under the MIT/X11 License. For more information, see http://randomlib.sourceforge.net/

Code for MixerMT0, MixerMT1, MixerSFMT.

MixerMT0 is adapted from MT19937 (init_by_array) and MT19937_64 (init_by_array64) by Makoto Matsumoto and Takuji Nishimura. See http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/CODES/mt19937ar.c and http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/VERSIONS/C-LANG/mt19937-64.c

MixerMT1 contains modifications to MixerMT0 by Charles Karney to correct defects in MixerMT0. This is described in W. E. Brown, M. Fischler, J. Kowalkowski, M. Paterno, Random Number Generation in C++0X: A Comprehensive Proposal, version 3, Sept 2006, Sec. 26.4.7.1, http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2079.pdf This has been replaced in the C++11 standard by MixerSFMT.

MixerSFMT is adapted from SFMT19937's init_by_array Mutsuo Saito given in http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/SFMT-src-1.2.tar.gz and is part of the C++11 standard; see P. Becker, Working Draft, Standard for Programming Language C++, Oct. 2007, Sec. 26.4.7.1, http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2461.pdf

The adaption to the C++ is copyright (c) Charles Karney (2006-2011) charl.nosp@m.es@k.nosp@m.arney.nosp@m..com and licensed under the MIT/X11 License. For more information, see http://randomlib.sourceforge.net/

Code for MT19937<T> and SFMT19937<T>.

MT19937<T> is adapted from MT19937 and MT19937_64 by Makoto Matsumoto and Takuji Nishimura. See http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/CODES/mt19937ar.c and http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/VERSIONS/C-LANG/mt19937-64.c

The code for stepping MT19937 backwards is adapted (and simplified) from revrand() by Katsumi Hagita. See http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/VERSIONS/FORTRAN/REVmt19937b.f

SFMT19937<T> is adapted from SFMT19937 Mutsuo Saito given in http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/M062821.pdf and http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/SFMT-src-1.2.tar.gz

The code for stepping SFMT19937 backwards is by Charles Karney.

The adaption to the C++ is copyright (c) Charles Karney (2006-2011) charl.nosp@m.es@k.nosp@m.arney.nosp@m..com and licensed under the MIT/X11 License. For more information, see http://randomlib.sourceforge.net/

Definition in file Random.cpp.

Macro Definition Documentation

#define RANDOMLIB_RANDOM_CPP   1

Definition at line 55 of file Random.cpp.

#define RANDOMLIB_BUILDING_LIBRARY   1

Let the header file know that the library is being built.

Definition at line 60 of file Random.cpp.

#define RANDOMLIB_WINDOWS   0

Definition at line 67 of file Random.cpp.

#define MT19937_STEP (   I,
  J,
 
)
Value:
statev[I] = statev[K] ^ \
(statev[J] & engine_type(1) ? magic : engine_type(0)) ^ \
((statev[I] & upper) | (statev[J] & lower)) >> 1

Definition at line 668 of file Random.cpp.

Referenced by RandomLib::MT19937< RandomType >::Transition().

#define MT19937_REVSTEP (   I,
  J,
 
)
Value:
{ \
engine_type q = statev[J] ^ statev[K], s = q >> (width - 1); \
q = (q ^ (s ? magic : engine_type(0))) << 1 | s; \
statev[I] = (p & upper) | (q & lower); \
p = q; \
}

Definition at line 679 of file Random.cpp.

Referenced by RandomLib::MT19937< RandomType >::Transition().

#define SFMT19937_STEP32 (   I,
 
)
Value:
{ \
internal_type t = statev[I] ^ statev[I] << 8 ^ \
(statev[J] >> 11 & magic0) ^ \
(s0 >> 8 | s1 << 24) ^ r0 << 18; \
s0 = r0; r0 = t & mask; \
t = statev[I + 1] ^ \
(statev[I + 1] << 8 | statev[I] >> 24) ^ \
(statev[J + 1] >> 11 & magic1) ^ \
(s1 >> 8 | s2 << 24) ^ r1 << 18; \
s1 = r1; r1 = t & mask; \
t = statev[I + 2] ^ \
(statev[I + 2] << 8 | statev[I + 1] >> 24) ^ \
(statev[J + 2] >> 11 & magic2) ^ \
(s2 >> 8 | s3 << 24) ^ r2 << 18; \
s2 = r2; r2 = t & mask; \
t = statev[I + 3] ^ \
(statev[I + 3] << 8 | statev[I + 2] >> 24) ^ \
(statev[J + 3] >> 11 & magic3) ^ s3 >> 8 ^ r3 << 18; \
s3 = r3; r3 = t & mask; \
statev[I ] = r0; statev[I + 1] = r1; \
statev[I + 2] = r2; statev[I + 3] = r3; \
}

Definition at line 989 of file Random.cpp.

Referenced by RandomLib::SFMT19937< RandomType >::Transition().

#define SFMT19937_REVSTEP32 (   I,
  J,
  K,
 
)
Value:
{ \
internal_type \
t0 = (statev[I] ^ (statev[J] >> 11 & magic0) ^ \
(statev[K] >> 8 | statev[K + 1] << 24) ^ \
statev[L] << 18) & mask, \
t1 = (statev[I + 1] ^ \
(statev[J + 1] >> 11 & magic1) ^ \
(statev[K + 1] >> 8 | statev[K + 2] << 24) ^ \
statev[L + 1] << 18) & mask, \
t2 = (statev[I + 2] ^ \
(statev[J + 2] >> 11 & magic2) ^ \
(statev[K + 2] >> 8 | statev[K + 3] << 24) ^ \
statev[L + 2] << 18) & mask, \
t3 = (statev[I + 3] ^ \
(statev[J + 3] >> 11 & magic3) ^ \
statev[K + 3] >> 8 ^ \
statev[L + 3] << 18) & mask; \
t3 ^= t1; t2 ^= t0; t3 ^= t2; t2 ^= t1; t1 ^= t0; \
t3 ^= t2 >> 16 | (t3 << 16 & mask); \
t2 ^= t1 >> 16 | (t2 << 16 & mask); \
t1 ^= t0 >> 16 | (t1 << 16 & mask); \
t0 ^= t0 << 16 & mask; \
statev[I ] = t0 ^ (t0 << 8 & mask); \
statev[I + 1] = t1 ^ (t0 >> 24 | (t1 << 8 & mask)); \
statev[I + 2] = t2 ^ (t1 >> 24 | (t2 << 8 & mask)); \
statev[I + 3] = t3 ^ (t2 >> 24 | (t3 << 8 & mask)); \
}

Definition at line 1012 of file Random.cpp.

Referenced by RandomLib::SFMT19937< RandomType >::Transition().

#define SFMT19937_STEP64 (   I,
 
)
Value:
{ \
internal_type t = statev[I] ^ statev[I] << 8 ^ \
(statev[J] >> 11 & magic0) ^ \
(s0 >> 8 | s1 << 56) ^ (r0 << 18 & mask18); \
s0 = r0; r0 = t & mask; \
t = statev[I + 1] ^ \
(statev[I + 1] << 8 | statev[I] >> 56) ^ \
(statev[J + 1] >> 11 & magic1) ^ \
s1 >> 8 ^ (r1 << 18 & mask18); \
s1 = r1; r1 = t & mask; \
statev[I] = r0; statev[I + 1] = r1; \
}

Definition at line 1073 of file Random.cpp.

Referenced by RandomLib::SFMT19937< RandomType >::Transition().

#define SFMT19937_REVSTEP64 (   I,
  J,
  K,
 
)
Value:
{ \
internal_type \
t0 = statev[I] ^ (statev[J] >> 11 & magic0) ^ \
(statev[K] >> 8 | (statev[K + 1] << 56 & mask)) ^ \
(statev[L] << 18 & mask18), \
t1 = statev[I + 1] ^ (statev[J + 1] >> 11 & magic1) ^ \
statev[K + 1] >> 8 ^ (statev[L + 1] << 18 & mask18); \
t1 ^= t0; \
t1 ^= t0 >> 32 ^ (t1 << 32 & mask); \
t0 ^= t0 << 32 & mask; \
t1 ^= t0 >> 48 ^ (t1 << 16 & mask); \
t0 ^= t0 << 16 & mask; \
statev[I ] = t0 ^ (t0 << 8 & mask); \
statev[I + 1] = t1 ^ t0 >> 56 ^ (t1 << 8 & mask); \
}

Definition at line 1091 of file Random.cpp.

Referenced by RandomLib::SFMT19937< RandomType >::Transition().