|
TPCCLIB
|
Header file for libtpcrand. More...
#include "tpcclibConfig.h"#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include <sys/time.h>#include <stdint.h>#include <inttypes.h>#include "tpcextensions.h"Go to the source code of this file.
Data Structures | |
| struct | MERTWI |
Macros | |
| #define | TPCCLIB_MERTWI_NN 312 |
| #define | TPCCLIB_MERTWI_A UINT64_C(0xB5026F5AA96619E9) |
Functions | |
| 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 | mertwiInit (MERTWI *mt) |
| 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. | |
| 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. | |
| double | mertwiRandomExponential (MERTWI *mt, double mean) |
| Generate pseudo-random number with exponential distribution and specified mean. | |
| 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. | |
| unsigned int | drandSeed (short int seed) |
| Make and optionally set the seed for rand(), drand, drandRange, and drandGaussian(). | |
| double | drand () |
| int | drandRange (unsigned int nr, double *d, double low, double up, int type) |
| double | drandGaussian () |
| Get pseudo-random number with normal (Gaussian) distribution with mean 0 and SD 1. | |
| double | drandExponential (double mean) |
| Get pseudo-random number with exponential distribution. | |
| void | randomShuffle (int *array, unsigned int n, MERTWI *mt) |
| Random shuffle. | |
| void | randomShuffleUnsigned (unsigned int *array, unsigned int n, MERTWI *mt) |
| Random shuffle. | |
| void | randomPermutation (int *array, unsigned int n, int a, MERTWI *mt) |
| Random permutation for an array of signed integers. | |
| void | randomPermutationUnsigned (unsigned int *array, unsigned int n, unsigned int a, MERTWI *mt) |
| Random permutation for an array of unsigned integers. | |
| int | haltonElement (const int i, const int dim, double *r) |
| Calculation of an element of quasi-random low-discrepancy Halton sequence. | |
| int | haltonPrime (const int N) |
| Subfunction for calculation of quasi-random Halton sequence. | |
Header file for libtpcrand.
Header file for library libtpcrand.
Definition in file tpcrand.h.
| #define TPCCLIB_MERTWI_A UINT64_C(0xB5026F5AA96619E9) |
Mersenne Twister required constant
Definition at line 29 of file tpcrand.h.
Referenced by mertwiInit(), and mertwiRandomInt64().
| #define TPCCLIB_MERTWI_NN 312 |
Mersenne Twister state vector length
Definition at line 27 of file tpcrand.h.
Referenced by mertwiInit().
|
extern |
Alternative function to rand() which returns a double precision floating point number in the range of [0,1] with uniform distribution.
Definition at line 66 of file gaussdev.c.
Referenced by drandExponential(), drandGaussian(), drandRange(), nloptPowellBrent(), and nloptRandomPoint().
|
extern |
Get pseudo-random number with exponential distribution.
| mean | Mean of the exponential distribution. |
Definition at line 178 of file gaussdev.c.
Referenced by nloptIATGO().
|
extern |
Get pseudo-random number with normal (Gaussian) distribution with mean 0 and SD 1.
Applies the polar form of Box-Müller transform to produce pseudo-random 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/
Definition at line 144 of file gaussdev.c.
Referenced by nloptGaussianPoint().
|
extern |
Fill the given double array with random numbers with uniform distribution between the specified limits.
With uniform distribution, the SD=(up-low)/sqrt(12), and CV=(up-low)/(sqrt(3)*(low+up)).
| nr | Nr of values in double array. |
| d | Pointer to pre-allocated double array. |
| low | Lower limit for random values. |
| up | Upper limit for random values. |
| type | Distribution: 0=even, 1=square-root transformation. |
Definition at line 90 of file gaussdev.c.
|
extern |
Make and optionally set the seed for rand(), drand, drandRange, and drandGaussian().
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.
| seed | Also sets seed with srand (1) or not (0). |
Definition at line 27 of file gaussdev.c.
|
extern |
Calculation of an element of quasi-random low-discrepancy Halton sequence.
| i | The index of the element to be calculated; 0<=I. |
| dim | The spatial dimension (size of element; number of parameters). |
| r | An array for the calculated element, of length DIM, containing values in range [0,1]. |
Definition at line 38 of file halton.c.
Referenced by nloptSimplexMS().
|
extern |
Subfunction for calculation of quasi-random Halton sequence.
| N | The index of the desired prime number; 0 <= N <= iMAX. N<0 returns iMAX, the index of the largest prime available. N=0 is legal, returning prime 1. N>iMAX returns zero, which should be interpreted as an error. |
Definition at line 75 of file halton.c.
Referenced by haltonElement().
|
extern |
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().
|
extern |
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.
|
extern |
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().
|
extern |
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.
|
extern |
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().
|
extern |
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. |
|
extern |
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. |
|
extern |
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().
|
extern |
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().
|
extern |
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().
|
extern |
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().
|
extern |
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().
|
extern |
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().
|
extern |
Random permutation for an array of signed integers.
Given (allocated) array of length n is filled with random permutation of numbers (signed integers) in the range [a:n+a-1]; that is, each number once in random order.
| array | Allocated array to be filled. |
| n | Length of array. |
| a | Smallest integer value. |
| mt | Pointer to data structure for Mersenne Twister MT19937 pseudo-random number generator. |
Definition at line 80 of file shuffle.c.
|
extern |
Random permutation for an array of unsigned integers.
Given (allocated) array of length n is filled with random permutation of numbers (unsigned integers) in the range [a:n+a-1]; that is, each number once in random order.
| array | Allocated array to be filled. |
| n | Length of array. |
| a | Smallest integer value. |
| mt | Pointer to data structure for Mersenne Twister MT19937 pseudo-random number generator. |
Definition at line 106 of file shuffle.c.
|
extern |
Random shuffle.
Arrange the n elements of integer array in random order. Only effective if N is much smaller than UINT64_MAX.
| array | Integer array to be shuffled. |
| n | Array length. |
| mt | Pointer to data structure for Mersenne Twister MT19937 pseudo-random number generator. |
Definition at line 27 of file shuffle.c.
Referenced by randomPermutation().
|
extern |
Random shuffle.
Arrange the n elements of unsigned integer array in random order. Only effective if N is much smaller than UINT64_MAX.
| array | Integer array to be shuffled. |
| n | Array length. |
| mt | Pointer to data structure for Mersenne Twister MT19937 pseudo-random number generator. |
Definition at line 54 of file shuffle.c.
Referenced by randomPermutationUnsigned().