MTToolBox  0.2.10
Data Structures | Functions | Variables
MTToolBox Namespace Reference

name space for MTToolBox More...

Data Structures

class  AbstractGenerator
 pseudo random number generator. More...
 
class  AlgorithmBestBits
 Algorithm which searches tempering parameters. More...
 
class  AlgorithmCalculateParity
 Calculate the parity check vector of reducible generator. More...
 
class  AlgorithmEquidistribution
 Calculate dimension of equi-distribution of output of pseudo random number generators. More...
 
class  AlgorithmPartialBitPattern
 Algorithm that search tempering parameters to improve dimension of equi-distribution of output of pseudo random number generator. More...
 
class  AlgorithmPrimitivity
 Algorithm which check if given polynomial is primitive. More...
 
class  AlgorithmRecursionAndTempering
 
class  AlgorithmRecursionSearch
 Search parameters of state transition function of pseudo random number generator so that the characteristic polynomial of the function will have max degree and will be primitive. More...
 
class  AlgorithmReducibleEquidistribution
 Calculate dimension of equi-distribution of reducible generator in worst case. More...
 
class  AlgorithmReducibleRecursionAndTempering
 
class  AlgorithmReducibleRecursionSearch
 Search parameters of state transition function of pseudo random number generator so that the characteristic polynomial of the function will have max degree and will be primitive. More...
 
class  AlgorithmTempering
 Algorithm that search tempering parameters to improve dimension of equi-distribution of output of pseudo random number generator. More...
 
class  EquidistributionCalculatable
 This class is an Abstract class for calculating dimension of equi-distribution for GF(2)-linear pseudo random number generators. More...
 
class  linear_generator_vector
 GF(2) pseudo random number generator as a GF(2) vector. More...
 
class  MersenneTwister
 Mersenne Twister pseudo random number generator. More...
 
class  MersenneTwister64
 Mersenne Twister pseudo random number generator. More...
 
class  RecursionSearchable
 
class  ReducibleGenerator
 This class is an Abstract class for reducible generator. More...
 
class  ReducibleTemperingCalculatable
 
class  Sequential
 Counting down number generator. More...
 
class  temper_params
 class which keeps tempering parameters More...
 
class  TemperingCalculatable
 Users can search tempering parameters by making GF(2)-linear pseudo random generator class which inherits from this class. More...
 
class  TestLinearity
 Checks if a pseudo random number generator is GF(2)-linear. More...
 

Functions

template<typename U , typename V = U>
void calcCharacteristicPolynomial (RecursionSearchable< U, V > *rand, NTL::GF2X &poly)
 
template<typename U , typename V = U>
void calcCharacteristicPolynomial (ReducibleGenerator< U, V > *rand, NTL::GF2X &poly)
 Calculate the characteristic polynomial of reducible generator. More...
 
template<typename U >
void minpoly (NTL::GF2X &poly, AbstractGenerator< U > &generator, int pos=0, int stateSize=0)
 Calculate minimal polynomial of output sequence. More...
 
bool isMexp (uint32_t degree)
 Returns if 2degree-1 is prime number. More...
 
bool isIrreducible (const NTL::GF2X &poly)
 Check if polynomial is irreducible. More...
 
bool isPrime (const NTL::GF2X &poly)
 Check if polynomial is primitive. More...
 
bool isPrime (const NTL::GF2X &poly, int degree, const NTL::Vec< NTL::ZZ > &prime_factors)
 Check if polynomial is primitive. More...
 
bool isPrime (const NTL::GF2X &poly, int degree, const char *prime_factors[])
 Check if polynomial is primitive. More...
 
bool hasFactorOfDegree (NTL::GF2X &poly, long degree)
 Check if primitive polynomial of given degree appears in factorization of poly. More...
 
template<typename U , typename V = U>
void annihilate (EquidistributionCalculatable< U, V > *rg, const NTL::GF2X &poly)
 Annihilate internal state of generator by given polynomial. More...
 
static int count_bit (uint16_t x)
 Counts number of 1s. More...
 
static int count_bit (uint32_t x)
 Counts number of 1s. More...
 
static int count_bit (uint64_t x)
 Counts number of 1s. More...
 
static uint32_t reverse_bit (uint32_t x)
 Reverse bits. More...
 
static uint64_t reverse_bit (uint64_t x)
 Counts number of 1s. More...
 
template<typename T >
int bit_size ()
 Returns bit size of T. More...
 
static void UNUSED_VARIABLE (void *x)
 Stop warning of unused variable. More...
 
template<typename T >
floor2p (T n)
 Return greatest power of two not greater than n. More...
 
static void print_binary (std::ostream &os, NTL::GF2X &poly, bool breakline=true)
 Outputs coefficients of poly to os. More...
 
template<typename T >
int get_range (T input, int start, int end)
 Changes input to number between start and end. More...
 
template<typename T >
void fill_table (T dist_tbl[], T src_tbl[], int size)
 Makes a fast and redundant lookup table from a tabale of GF(2) vectors. More...
 
static int calc_1pos (uint16_t x)
 Returns the position of 1 which appears lowest (most right side) in x, where the position of MSB becomes zero. More...
 
static int calc_1pos (uint32_t x)
 Returns the position of 1 which appears lowest (most right side) in x, where the position of MSB becomes zero. More...
 
static int calc_1pos (uint64_t x)
 Returns the position of 1 which appears lowest (most right side) in x, where the position of MSB becomes zero. More...
 
static void LCM (NTL::GF2X &lcm, const NTL::GF2X &x, const NTL::GF2X &y)
 Calculate the Least Common Multiple of x and y. More...
 
template<typename U >
static void toGF2Vec (NTL::vec_GF2 &result, U value)
 convert unsigned integer to GF(2) vector MSB of unsigned integer becomes first element of the vector. More...
 
template<typename U >
getOne ()
 return one of specified type More...
 
template<typename U >
void setZero (U &x)
 set zero More...
 
template<typename U >
unsigned int getBitOfPos (U bits, int pos)
 set zero More...
 
template<typename U >
void setBitOfPos (U *bits, int pos, unsigned int b)
 set zero or 1 to specified bit of specified type variable. More...
 
template<typename U >
static U fromGF2Vec (NTL::vec_GF2 &value)
 convert GF(2) vector to unsigned integer the first element of vector becomes the MSB of the result integer. More...
 
template<typename U >
bool isZero (U x)
 check if varible is zero or not More...
 
template<typename U , typename V >
convert (V x)
 convert to type U from type V More...
 
const char * get_mttoolbox_version ()
 returns library version More...
 

Variables

const AlgorithmPrimitivity MersennePrimitivity
 An algorithm which checks if given polynomial is a primitive polynomial of given degree for pseudo random number generator whose internal state size is Mersenne exponent. More...
 
const char * prime_factors2_128_1 []
 List of prime numbers appear in the factorization of 2128-1. More...
 
const char * prime_factors2_160_1 []
 List of prime numbers appear in the factorization of 2160-1. More...
 
const char * prime_factors2_192_1 []
 List of prime numbers appear in the factorization of 2192-1. More...
 
const char * prime_factors2_224_1 []
 List of prime numbers appear in the factorization of 2224-1. More...
 
const char * prime_factors2_256_1 []
 List of prime numbers appear in the factorization of 2256-1. More...
 
const char * prime_factors2_288_1 []
 List of prime numbers appear in the factorization of 2288-1. More...
 
const char * prime_factors2_320_1 []
 List of prime numbers appear in the factorization of 2320-1. More...
 
const char * prime_factors2_352_1 []
 List of prime numbers appear in the factorization of 2352-1. More...
 
const char * prime_factors2_384_1 []
 List of prime numbers appear in the factorization of 2384-1. More...
 
const char * prime_factors2_416_1 []
 List of prime numbers appear in the factorization of 2416-1. More...
 
const char * prime_factors2_448_1 []
 List of prime numbers appear in the factorization of 2448-1. More...
 
const char * prime_factors2_480_1 []
 List of prime numbers appear in the factorization of 2480-1. More...
 
const char * prime_factors2_512_1 []
 List of prime numbers appear in the factorization of 2512-1. More...
 
const char * prime_factors2_544_1 []
 List of prime numbers appear in the factorization of 2544-1. More...
 

Detailed Description

name space for MTToolBox

Function Documentation

template<typename U , typename V = U>
void MTToolBox::annihilate ( EquidistributionCalculatable< U, V > *  rg,
const NTL::GF2X &  poly 
)

Annihilate internal state of generator by given polynomial.

Template Parameters
Uoutput type of the generator.
Voutput type of the generator used for parameter generating.
Parameters
[in,out]rgreducible generator
[in]polyannihilator polynomial

References MTToolBox::EquidistributionCalculatable< U, V >::add(), MTToolBox::EquidistributionCalculatable< U, V >::clone(), MTToolBox::EquidistributionCalculatable< U, V >::generate(), and MTToolBox::EquidistributionCalculatable< U, V >::setZero().

Referenced by MTToolBox::AlgorithmReducibleRecursionAndTempering< U, G >::search().

template<typename T >
int MTToolBox::bit_size ( )

Returns bit size of T.

This is not correct because just multiply sizeof(T) by eight.

Template Parameters
Ttype
Returns
bit size of T
static int MTToolBox::calc_1pos ( uint16_t  x)
inlinestatic

Returns the position of 1 which appears lowest (most right side) in x, where the position of MSB becomes zero.

Algorithm to search position of 1 is from this page;

See also
http://aggregate.org/MAGIC/#Trailing Zero Count
Parameters
[in]xinput
Returns
the position of 1 which appears lowest (most right side) in x, where the position of MSB becomes zero.

References count_bit().

static int MTToolBox::calc_1pos ( uint32_t  x)
inlinestatic

Returns the position of 1 which appears lowest (most right side) in x, where the position of MSB becomes zero.

Algorithm to search position of 1 is from this page;

See also
http://aggregate.org/MAGIC/#Trailing Zero Count
Parameters
[in]xinput
Returns
the position of 1 which appears lowest (most right side) in x, where the position of MSB becomes zero. Example
  • calc_1pos(0x80000000U) returns 0.
  • calc_1pos(0x80000002U) returns 30.
  • calc_1pos(0) returns -1.
Parameters
[in]xinput
Returns
the position of 1 which appears lowest (most right side) in x, where the position of MSB becomes zero.

References count_bit().

static int MTToolBox::calc_1pos ( uint64_t  x)
inlinestatic

Returns the position of 1 which appears lowest (most right side) in x, where the position of MSB becomes zero.

Algorithm to search position of 1 is from this page;

See also
http://aggregate.org/MAGIC/#Trailing Zero Count
Parameters
[in]xinput
Returns
the position of 1 which appears lowest (most right side) in x, where the position of MSB becomes zero. Example
  • calc_1pos(UINT64_C(0x8000000000000000)) returns 0.
  • calc_1pos(UINT64_C(0x8000000000000002)) returns 62.
  • calc_1pos(0) returns -1.
Parameters
[in]xinput
Returns
the position of 1 which appears lowest (most right side) in x, where the position of MSB becomes zero.

References count_bit().

template<typename U , typename V = U>
void MTToolBox::calcCharacteristicPolynomial ( RecursionSearchable< U, V > *  rand,
NTL::GF2X &  poly 
)
template<typename U , typename V = U>
void MTToolBox::calcCharacteristicPolynomial ( ReducibleGenerator< U, V > *  rand,
NTL::GF2X &  poly 
)

Calculate the characteristic polynomial of reducible generator.

Template Parameters
Utype of return value of random number generator.
Vtype of return value of parameter generator.
Parameters
[in,out]randpseudo random number generator.
[in,out]polycalculated characteristic polynomial.

References MTToolBox::AbstractGenerator< U >::bitSize(), LCM(), and minpoly().

template<typename U , typename V >
U MTToolBox::convert ( x)
inline

convert to type U from type V

Template Parameters
Utype convert to
Vtype convert from
Parameters
[in]xvariable
Returns
value of type U
static int MTToolBox::count_bit ( uint16_t  x)
inlinestatic

Counts number of 1s.

SIMD within a Register algorithm citing from a website http://aggregate.org/MAGIC/

Parameters
[in]xbit pattern
Returns
number of 1s in x.

Referenced by calc_1pos().

static int MTToolBox::count_bit ( uint32_t  x)
inlinestatic

Counts number of 1s.

SIMD within a Register algorithm citing from a website http://aggregate.org/MAGIC/

Parameters
[in]xbit pattern
Returns
number of 1s in x.
Parameters
[in]xbit pattern
Returns
number of 1s in x.
static int MTToolBox::count_bit ( uint64_t  x)
inlinestatic

Counts number of 1s.

SIMD within a Register algorithm citing from a website http://aggregate.org/MAGIC/

Parameters
[in]xbit pattern
Returns
number of 1s in x.
Parameters
[in]xbit pattern
Returns
number of 1s in x.
template<typename T >
void MTToolBox::fill_table ( dist_tbl[],
src_tbl[],
int  size 
)

Makes a fast and redundant lookup table from a tabale of GF(2) vectors.

Template Parameters
Ttype of elements in tables.
Parameters
[out]dist_tbla lookup table to be made
[in]src_tbltable of GF(2) vectors.
[in]sizesize of dist_tbl
template<typename T >
T MTToolBox::floor2p ( n)

Return greatest power of two not greater than n.

Template Parameters
Ttype of n
Parameters
[in]ninteger
Returns
greatest 2x < = n
template<typename U >
static U MTToolBox::fromGF2Vec ( NTL::vec_GF2 &  value)
inlinestatic

convert GF(2) vector to unsigned integer the first element of vector becomes the MSB of the result integer.

Parameters
[in]valuesource vector
Returns
resulted integer

References setBitOfPos(), and setZero().

const char* MTToolBox::get_mttoolbox_version ( )

returns library version

Returns
library version string
template<typename T >
int MTToolBox::get_range ( input,
int  start,
int  end 
)

Changes input to number between start and end.

This conversion may not be uniformly distributed.

Parameters
[in]inputinput
[in]startstart of range
[in]endend of range
Returns
r satisfies that start <= r <= end
template<typename U >
unsigned int MTToolBox::getBitOfPos ( bits,
int  pos 
)
inline

set zero

Template Parameters
Utype to get bit
Parameters
[in]bitsvariable to get bit
[in]posbit position
Returns
bit of position, zero or one.

Referenced by minpoly().

template<typename U >
U MTToolBox::getOne ( )
inline

return one of specified type

Template Parameters
Utype of one
Returns
one of specified type
bool MTToolBox::hasFactorOfDegree ( NTL::GF2X &  poly,
long  degree 
)

Check if primitive polynomial of given degree appears in factorization of poly.

This function will be used by SFMT and dSFMT.

Parameters
[in,out]polypolynomial over GF(2)
[in]degreeif poly has primitive polynomial with degree in its factors.
Returns
true if poly has primitive polynomial with degree.

Referenced by MTToolBox::AlgorithmReducibleRecursionSearch< U, V >::start().

bool MTToolBox::isIrreducible ( const NTL::GF2X &  poly)

Check if polynomial is irreducible.

Parameters
[in]polypolynomial whose coefficients are GF(2)
Returns
true if poly is irreducible
bool MTToolBox::isMexp ( uint32_t  degree)

Returns if 2degree-1 is prime number.

This is checked by fixed list of exponents of Mersenne Prime, therefore this check is not complete.

Parameters
[in]degreenumber to be checked
Returns
true if 2degree -1 is prime number.
bool MTToolBox::isPrime ( const NTL::GF2X &  poly)

Check if polynomial is primitive.

This check is lazy check. Only if degree of polynomial is Mersenne Exponent, the result is correct. This check should not be used, when bit size of internal state is not Mersenne Exponent.

Parameters
[in]polypolynomial over GF(2)
Returns
true if polynomial is primitive

Referenced by MTToolBox::AlgorithmRecursionSearch< U, V >::AlgorithmRecursionSearch(), MTToolBox::AlgorithmRecursionAndTempering< U, V >::search(), and MTToolBox::AlgorithmRecursionSearch< U, V >::start().

bool MTToolBox::isPrime ( const NTL::GF2X &  poly,
int  degree,
const NTL::Vec< NTL::ZZ > &  prime_factors 
)

Check if polynomial is primitive.

This function returns false if degree of polynomial is not degree. Users should give a list of primes which appear in integer factorization of 2degree-1.

Parameters
[in]polypolynomial over GF(2)
[in]degreepoly expected to have degree.
[in]prime_factorsa list of primes which appear in integer factorization of 2degree-1.
bool MTToolBox::isPrime ( const NTL::GF2X &  poly,
int  degree,
const char *  prime_factors[] 
)

Check if polynomial is primitive.

This function returns false if degree of polynomial is not degree. Users should give a list of primes which app-er in integer factorization of 2degree-1.

Parameters
[in]polypolynomial over GF(2)
[in]degreepoly expected to have degree.
[in]prime_factorsa list of primes which appear in integer factorization of 2degree-1.
template<typename U >
bool MTToolBox::isZero ( x)
inline

check if varible is zero or not

Template Parameters
Utype of variable
Parameters
[in]xvariable to be checked
Returns
ture if x is zero

Referenced by MTToolBox::linear_generator_vector< U, V >::next_state(), and MTToolBox::AlgorithmCalculateParity< U, G >::searchParity().

static void MTToolBox::LCM ( NTL::GF2X &  lcm,
const NTL::GF2X &  x,
const NTL::GF2X &  y 
)
inlinestatic

Calculate the Least Common Multiple of x and y.

Parameters
[out]lcmthe Least Common Multiple of x and y.
[in]xa polynomial
[in]ya polynomial

Referenced by calcCharacteristicPolynomial().

template<typename U >
void MTToolBox::minpoly ( NTL::GF2X &  poly,
AbstractGenerator< U > &  generator,
int  pos = 0,
int  stateSize = 0 
)

Calculate minimal polynomial of output sequence.

Template Parameters
Utype of output of pseudo random number generator
Parameters
[out]polyminimal polynomial
[in]generatorGF(2)-linear pseudo random number generator
[in]posspecifies how manieth bit from LSB is checked, zero means LSB.
[in]stateSizebit size of internal state.

References MTToolBox::AbstractGenerator< U >::bitSize(), MTToolBox::AbstractGenerator< U >::generate(), and getBitOfPos().

Referenced by calcCharacteristicPolynomial(), MTToolBox::AlgorithmReducibleRecursionSearch< U, V >::start(), and MTToolBox::AlgorithmRecursionSearch< U, V >::start().

static void MTToolBox::print_binary ( std::ostream &  os,
NTL::GF2X &  poly,
bool  breakline = true 
)
inlinestatic

Outputs coefficients of poly to os.

Coefficients of low degree terms are outputted first.

Parameters
[in,out]osoutput stream
[in]polypolynomial to be outputted
[in]breaklineif true, line break after every 32 terms.
static uint32_t MTToolBox::reverse_bit ( uint32_t  x)
inlinestatic

Reverse bits.

Reverse upper side and lower side in input. The MSB bocomes the LSB. SIMD within a Register algorithm citing from a website http://aggregate.org/MAGIC/

Parameters
[in]xbit pattern
Returns
reverse of x
static uint64_t MTToolBox::reverse_bit ( uint64_t  x)
inlinestatic

Counts number of 1s.

SIMD within a Register algorithm citing from a website http://aggregate.org/MAGIC/

Parameters
[in]xbit pattern
Returns
number of 1s in x.
Parameters
[in]xbit pattern
Returns
number of 1s in x.
Parameters
[in]xbit pattern
Returns
reverse of x
template<typename U >
void MTToolBox::setBitOfPos ( U *  bits,
int  pos,
unsigned int  b 
)
inline

set zero or 1 to specified bit of specified type variable.

Template Parameters
Utype of variable
Parameters
[in,out]bitsvariable
[in]posposition of bit, LSB is 0
[in]bbit to set

Referenced by fromGF2Vec().

template<typename U >
void MTToolBox::setZero ( U &  x)
inline

set zero

Template Parameters
Utype to set zero
Parameters
[out]xvariable set to be zero

Referenced by fromGF2Vec(), MTToolBox::linear_generator_vector< U, V >::linear_generator_vector(), and MTToolBox::AlgorithmCalculateParity< U, G >::searchParity().

template<typename U >
static void MTToolBox::toGF2Vec ( NTL::vec_GF2 &  result,
value 
)
inlinestatic

convert unsigned integer to GF(2) vector MSB of unsigned integer becomes first element of the vector.

Template Parameters
Utype of conversion source
Parameters
[out]resultThe result vector
[in]valuesource integer
static void MTToolBox::UNUSED_VARIABLE ( void *  x)
inlinestatic

Stop warning of unused variable.

Parameters
[in]xpointer to unused variable

Variable Documentation

const AlgorithmPrimitivity MTToolBox::MersennePrimitivity

An algorithm which checks if given polynomial is a primitive polynomial of given degree for pseudo random number generator whose internal state size is Mersenne exponent.

Referenced by MTToolBox::AlgorithmRecursionSearch< U, V >::AlgorithmRecursionSearch().

const char* MTToolBox::prime_factors2_128_1[]

List of prime numbers appear in the factorization of 2128-1.

const char* MTToolBox::prime_factors2_160_1[]

List of prime numbers appear in the factorization of 2160-1.

const char* MTToolBox::prime_factors2_192_1[]

List of prime numbers appear in the factorization of 2192-1.

const char* MTToolBox::prime_factors2_224_1[]

List of prime numbers appear in the factorization of 2224-1.

const char* MTToolBox::prime_factors2_256_1[]

List of prime numbers appear in the factorization of 2256-1.

const char* MTToolBox::prime_factors2_288_1[]

List of prime numbers appear in the factorization of 2288-1.

const char* MTToolBox::prime_factors2_320_1[]

List of prime numbers appear in the factorization of 2320-1.

const char* MTToolBox::prime_factors2_352_1[]

List of prime numbers appear in the factorization of 2352-1.

const char* MTToolBox::prime_factors2_384_1[]

List of prime numbers appear in the factorization of 2384-1.

const char* MTToolBox::prime_factors2_416_1[]

List of prime numbers appear in the factorization of 2416-1.

const char* MTToolBox::prime_factors2_448_1[]

List of prime numbers appear in the factorization of 2448-1.

const char* MTToolBox::prime_factors2_480_1[]

List of prime numbers appear in the factorization of 2480-1.

const char* MTToolBox::prime_factors2_512_1[]

List of prime numbers appear in the factorization of 2512-1.

const char* MTToolBox::prime_factors2_544_1[]

List of prime numbers appear in the factorization of 2544-1.