|
TPCCLIB
|
Mersenne Twister MT19937 pseudo-random number generator for TPCCLIB. More...
#include "tpcclibConfig.h"#include <stdio.h>#include <stdlib.h>#include <math.h>#include <unistd.h>#include <time.h>#include <sys/time.h>#include "tpcextensions.h"#include "tpcrand.h"Go to the source code of this file.
Functions | |
| void | mertwiInit (MERTWI *mt) |
| uint32_t | mertwiSeed32 (void) |
| Make uint32_t seed for pseudo-random number generators. | |
| uint64_t | mertwiSeed64 (void) |
| Make uint64_t seed for pseudo-random number generators. | |
| void | mertwiInitWithSeed64 (MERTWI *mt, uint64_t seed) |
| Initialize the state vector mt[] inside data structure for Mersenne Twister MT19937 pseudo-random number generator using given seed. | |
| void | mertwiInitByArray64 (MERTWI *mt, uint64_t init_key[], uint64_t key_length) |
| Initialize the state vector mt[] inside data structure for Mersenne Twister MT19937 pseudo-random number generator using given array. | |
| uint64_t | mertwiRandomInt64 (MERTWI *mt) |
| Generate a random number on [0, 2^64-1]-interval using Mersenne Twister MT19937. | |
| int64_t | mertwiRandomInt63 (MERTWI *mt) |
| Generate a random number on [0, 2^63-1]-interval using Mersenne Twister MT19937. | |
| double | mertwiRandomDouble1 (MERTWI *mt) |
| Generate a 64-bit double precision floating point pseudo-random number in the range of [0,1] with uniform distribution using Mersenne Twister MT19937. | |
| double | mertwiRandomDouble2 (MERTWI *mt) |
| Generate a 64-bit double precision floating point pseudo-random number in the range of [0,1) with uniform distribution using Mersenne Twister MT19937. | |
| double | mertwiRandomDouble3 (MERTWI *mt) |
| Generate a 64-bit double precision floating point pseudo-random number in the range of (0,1) with uniform distribution using Mersenne Twister MT19937. | |
| int | mertwiRandomBetween (MERTWI *mt, unsigned int nr, double *d, double low, double up, int type) |
| Fill the given double array with random numbers with uniform distribution between the specified limits. | |
| double | mertwiRandomExponential (MERTWI *mt, double mean) |
| Generate pseudo-random number with exponential distribution and specified mean. | |
| double | mertwiRandomGaussian (MERTWI *mt) |
| Generate a 64-bit double precision floating point pseudo-random number with normal (Gaussian) distribution with zero mean 0 and SD 1. | |
Mersenne Twister MT19937 pseudo-random number generator for TPCCLIB.
For more information on the method and original source codes visit https://www.math.sci.hiroshima-u.ac.jp/m-mat/MT/emt.html
Definition in file mertwi.c.
| void mertwiInit | ( | MERTWI * | mt | ) |
Prepare the data structure of Mersenne Twister MT19937 for usage. Do not call any mertwi* functions before calling this function!
| mt | Pointer to data structure for Mersenne Twister MT19937 pseudo-random number generator. |
Definition at line 28 of file mertwi.c.
Referenced by nloptMPSO().
| void mertwiInitByArray64 | ( | MERTWI * | mt, |
| uint64_t | init_key[], | ||
| uint64_t | key_length ) |
Initialize the state vector mt[] inside data structure for Mersenne Twister MT19937 pseudo-random number generator using given array.
Call either this or mertwiInitWithSeed64 before generating random numbers with MT19937 using functions.
| mt | Pointer to data structure for Mersenne Twister MT19937 pseudo-random number generator. |
| init_key | The array for initializing keys. |
| key_length | Length of initialization array init_key[]. |
Definition at line 113 of file mertwi.c.
| void mertwiInitWithSeed64 | ( | MERTWI * | mt, |
| uint64_t | seed ) |
Initialize the state vector mt[] inside data structure for Mersenne Twister MT19937 pseudo-random number generator using given seed.
Call either this or mertwiInitByArray64 before generating random numbers with MT19937 using functions.
| mt | Pointer to data structure for Mersenne Twister MT19937 pseudo-random number generator. |
| seed | Seed, for example from mertwiSeed64(). |
Definition at line 94 of file mertwi.c.
Referenced by mertwiInitByArray64(), mertwiRandomInt64(), and nloptMPSO().
| int mertwiRandomBetween | ( | MERTWI * | mt, |
| unsigned int | nr, | ||
| double * | d, | ||
| double | low, | ||
| double | up, | ||
| int | type ) |
Fill the given double array with random numbers with uniform distribution between the specified limits.
Applies Mersenne Twister MT19937 pseudo-random number generator. With uniform distribution, the SD=(up-low)/sqrt(12), and CV=(up-low)/(sqrt(3)*(low+up)).
| mt | Pointer to data structure for Mersenne Twister MT19937 pseudo-random number generator. |
| nr | Number of values in double array d[]. |
| d | Pointer to pre-allocated double array, to be filled here. |
| low | Lower limit for random values. |
| up | Upper limit for random values. |
| type | Distribution: 0=even, 1=square-root transformation. |
Definition at line 270 of file mertwi.c.
| double mertwiRandomDouble1 | ( | MERTWI * | mt | ) |
Generate a 64-bit double precision floating point pseudo-random number in the range of [0,1] with uniform distribution using Mersenne Twister MT19937.
With uniform distribution, the SD=(up-low)/sqrt(12), and CV=(up-low)/(sqrt(3)*(low+up)).
| mt | Pointer to data structure for Mersenne Twister MT19937 pseudo-random number generator. |
Definition at line 216 of file mertwi.c.
Referenced by mertwiRandomBetween(), mertwiRandomExponential(), mertwiRandomGaussian(), nloptMPSO(), and nloptRandomPoint().
| double mertwiRandomDouble2 | ( | MERTWI * | mt | ) |
Generate a 64-bit double precision floating point pseudo-random number in the range of [0,1) with uniform distribution using Mersenne Twister MT19937.
| mt | Pointer to data structure for Mersenne Twister MT19937 pseudo-random number generator. |
| double mertwiRandomDouble3 | ( | MERTWI * | mt | ) |
Generate a 64-bit double precision floating point pseudo-random number in the range of (0,1) with uniform distribution using Mersenne Twister MT19937.
| mt | Pointer to data structure for Mersenne Twister MT19937 pseudo-random number generator. |
| double mertwiRandomExponential | ( | MERTWI * | mt, |
| double | mean ) |
Generate pseudo-random number with exponential distribution and specified mean.
Applies Mersenne Twister MT19937 pseudo-random number generator.
| mt | Pointer to data structure for Mersenne Twister MT19937 pseudo-random number generator. |
| mean | Mean of the exponential distribution. |
Definition at line 322 of file mertwi.c.
Referenced by nloptMPSO().
| double mertwiRandomGaussian | ( | MERTWI * | mt | ) |
Generate a 64-bit double precision floating point pseudo-random number with normal (Gaussian) distribution with zero mean 0 and SD 1.
Applies Mersenne Twister MT19937 pseudo-random number generator, and the polar form of Box-Müller transform to produce numbers with Gaussian (normal) distribution which has a zero mean and standard deviation of one.
Box GEP, Muller ME. A note on the generation of random normal deviates. Annals of Mathematical Statistics, Volume 29, Issue 2, 1958, 610-611. Available from JSTOR https://www.jstor.org/
| mt | Pointer to data structure for Mersenne Twister MT19937 pseudo-random number generator. |
Definition at line 354 of file mertwi.c.
Referenced by nloptGaussianPoint().
| int64_t mertwiRandomInt63 | ( | MERTWI * | mt | ) |
Generate a random number on [0, 2^63-1]-interval using Mersenne Twister MT19937.
| mt | Pointer to data structure for Mersenne Twister MT19937 pseudo-random number generator. |
Definition at line 197 of file mertwi.c.
Referenced by nloptMPSO().
| uint64_t mertwiRandomInt64 | ( | MERTWI * | mt | ) |
Generate a random number on [0, 2^64-1]-interval using Mersenne Twister MT19937.
| mt | Pointer to data structure for Mersenne Twister MT19937 pseudo-random number generator. |
Definition at line 153 of file mertwi.c.
Referenced by mertwiRandomDouble1(), mertwiRandomDouble2(), mertwiRandomDouble3(), mertwiRandomInt63(), randomShuffle(), and randomShuffleUnsigned().
| uint32_t mertwiSeed32 | ( | void | ) |
Make uint32_t seed for pseudo-random number generators.
Uses microseconds from the computer clock and process ID to reduce the chance of getting the same seed for simultaneously executing program threads and instances.
Definition at line 48 of file mertwi.c.
Referenced by mertwiSeed64().
| uint64_t mertwiSeed64 | ( | void | ) |
Make uint64_t seed for pseudo-random number generators.
Uses microseconds from the computer clock and process ID to reduce the chance of getting the same seed for simultaneously executing program threads and instances.
Definition at line 76 of file mertwi.c.
Referenced by nloptMPSO().