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

namespace  RandomLib

Defines

#define RANDOM_CPP   "$Id: Random.cpp 6505 2009-01-12 03:34:23Z ckarney $"
#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)

Functions

 RCSID_DECL (RANDOM_CPP)
 RCSID_DECL (RANDOMTYPE_HPP)
 RCSID_DECL (RANDOMSEED_HPP)
 RCSID_DECL (RANDOMENGINE_HPP)
 RCSID_DECL (RANDOMMIXER_HPP)
 RCSID_DECL (RANDOMALGORITHM_HPP)
 RCSID_DECL (RANDOMPOWER2_HPP)
 RCSID_DECL (RANDOMCANONICAL_HPP)

Detailed Description

Implementation code for RandomLib.

Written by Charles Karney <charles@karney.com> and licensed under the LGPL. For more information, see http://charles.karney.info/random/

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++0X proposal by MixerSFMT.

RandonMixer2 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++0X proposal; 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 by Charles Karney <charles@karney.com> and licensed under the LGPL. For more information, see http://charles.karney.info/random/

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 by Charles Karney <charles@karney.com> and licensed under the LGPL. For more information, see http://charles.karney.info/random/

Definition in file Random.cpp.


Define Documentation

#define RANDOM_CPP   "$Id: Random.cpp 6505 2009-01-12 03:34:23Z ckarney $"

Definition at line 76 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 671 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 682 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 991 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 1014 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 1074 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 1092 of file Random.cpp.

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


Function Documentation

RCSID_DECL ( RANDOM_CPP   ) 
RCSID_DECL ( RANDOMTYPE_HPP   ) 
RCSID_DECL ( RANDOMSEED_HPP   ) 
RCSID_DECL ( RANDOMENGINE_HPP   ) 
RCSID_DECL ( RANDOMMIXER_HPP   ) 
RCSID_DECL ( RANDOMALGORITHM_HPP   ) 
RCSID_DECL ( RANDOMPOWER2_HPP   ) 
RCSID_DECL ( RANDOMCANONICAL_HPP   ) 

Generated on Thu Dec 31 15:24:29 2009 by  doxygen 1.6.1