#include <string.h>
#include <assert.h>
#include <stdio.h>
#include <stdint.h>
Go to the source code of this file.
Data Structures | |
| struct | MTGP32_PARAMS_FAST_T |
| MTGP32 parameters. More... | |
| struct | MTGP32_STATUS_FAST_T |
| MTGP32 internal state array. More... | |
| struct | MTGP32_FAST_T |
Typedefs | |
| typedef struct MTGP32_PARAMS_FAST_T | mtgp32_params_fast_t |
| typedef struct MTGP32_STATUS_FAST_T | mtgp32_status_fast_t |
| typedef struct MTGP32_FAST_T | mtgp32_fast_t |
Functions | |
| int | mtgp32_init (mtgp32_fast_t *mtgp32, const mtgp32_params_fast_t *para, uint32_t seed) |
| This function allocates and initializes the internal state array with a 32-bit integer seed. | |
| void | mtgp32_init_state (uint32_t array[], const mtgp32_params_fast_t *para, uint32_t seed) |
| This function initializes the internal state array with a 32-bit integer seed. | |
| int | mtgp32_init_by_array (mtgp32_fast_t *mtgp32, const mtgp32_params_fast_t *para, uint32_t *array, int length) |
| This function allocates and initializes the internal state array with a 32-bit integer array. | |
| int | mtgp32_init_by_str (mtgp32_fast_t *mtgp32, const mtgp32_params_fast_t *para, char *str) |
| This function allocates and initializes the internal state array with a character array. | |
| void | mtgp32_free (mtgp32_fast_t *mtgp32) |
| This releases the memory allocated by mtgp32_init(), mtgp32_init_by_array(), mtgp32_init_by_str(). | |
| void | mtgp32_print_idstring (const mtgp32_fast_t *mtgp32, FILE *fp) |
| This function prints the Mersenne exponent and SHA1 of characteristic polynomial of generators state transition function. | |
| static void | mtgp32_do_recursion (uint32_t *r, uint32_t x1, uint32_t x2, uint32_t y, int sh1, int sh2, uint32_t mask, uint32_t tbl[16]) |
| This is a recursion formula of the generator. | |
| static void | mtgp32_next_state (mtgp32_fast_t *mtgp32) |
| The state transition function. | |
| static uint32_t | mtgp32_genrand_uint32 (mtgp32_fast_t *mtgp32) |
| This function generates and returns 32-bit unsigned integer. | |
| static float | mtgp32_genrand_close1_open2 (mtgp32_fast_t *mtgp32) |
| This function generates and returns single precision pseudorandom number which distributes uniformly in the range [1, 2). | |
| static float | mtgp32_genrand_close_open (mtgp32_fast_t *mtgp32) |
| This function generates and returns single precision pseudorandom number which distributes uniformly in the range [0, 1). | |
| static float | mtgp32_genrand_open_close (mtgp32_fast_t *mtgp32) |
| This function generates and returns single precision pseudorandom number which distributes uniformly in the range (0, 1]. | |
| static float | mtgp32_genrand_open_open (mtgp32_fast_t *mtgp32) |
| This function generates and returns single precision pseudorandom number which distributes uniformly in the range (0, 1). | |
| static uint32_t | mtgp32_temper (const uint32_t tmp_tbl[16], uint32_t r, uint32_t t) |
| The tempering function. | |
| static float | mtgp32_temper_float (const uint32_t flt_tmp_tbl[16], uint32_t r, uint32_t t) |
| The tempering and converting function. | |
| static float | mtgp32_temper_float_open (const uint32_t flt_tmp_tbl[16], uint32_t r, uint32_t t) |
| The tempering and converting function for generating floating point number f (0 < f < 1). | |
Variables | |
| mtgp32_params_fast_t | mtgp32_params_fast_11213 [128] |
| parameter constants tables for MEXP=11213. | |
| mtgp32_params_fast_t | mtgp32_params_fast_23209 [128] |
| parameter constants tables for MEXP=23209. | |
| mtgp32_params_fast_t | mtgp32_params_fast_44497 [128] |
| parameter constants tables for MEXP=44497. | |
Copyright (C) 2009 Mutsuo Saito, Makoto Matsumoto and Hiroshima University. All rights reserved.
The new BSD License is applied to this software, see LICENSE.txt
| typedef struct MTGP32_FAST_T mtgp32_fast_t |
| typedef struct MTGP32_PARAMS_FAST_T mtgp32_params_fast_t |
| typedef struct MTGP32_STATUS_FAST_T mtgp32_status_fast_t |
| static void mtgp32_do_recursion | ( | uint32_t * | r, | |
| uint32_t | x1, | |||
| uint32_t | x2, | |||
| uint32_t | y, | |||
| int | sh1, | |||
| int | sh2, | |||
| uint32_t | mask, | |||
| uint32_t | tbl[16] | |||
| ) | [inline, static] |
This is a recursion formula of the generator.
MTGP32 is a 32-bit generator, but using 32-bit operations to fit to graphic processors.
| [out] | r | output |
| [in] | x1 | the farthest part of state array. |
| [in] | x2 | the second farthest part of state array. |
| [in] | y | a part of state array. |
| [in] | sh1 | the shift parameter 1. |
| [in] | sh2 | the shift parameter 2. |
| [in] | mask | the bit mask parameter. |
| [in] | tbl | the matrix parameter. |
Referenced by mtgp32_next_state().
| void mtgp32_free | ( | mtgp32_fast_t * | mtgp32 | ) |
This releases the memory allocated by mtgp32_init(), mtgp32_init_by_array(), mtgp32_init_by_str().
| [in,out] | mtgp32 | MTGP all in one structure. |
References MTGP32_FAST_T::status.
| static float mtgp32_genrand_close1_open2 | ( | mtgp32_fast_t * | mtgp32 | ) | [inline, static] |
This function generates and returns single precision pseudorandom number which distributes uniformly in the range [1, 2).
mtgp32_init(), mtgp32_init_by_array() or mtgp32_init_by_str() must be called before this function.
| [in,out] | mtgp32 | MTGP all in one structure. |
References MTGP32_STATUS_FAST_T::array, MTGP32_PARAMS_FAST_T::flt_tmp_tbl, MTGP32_STATUS_FAST_T::idx, MTGP32_STATUS_FAST_T::large_mask, MTGP32_STATUS_FAST_T::large_size, mtgp32_next_state(), mtgp32_temper_float(), MTGP32_FAST_T::params, MTGP32_PARAMS_FAST_T::pos, MTGP32_STATUS_FAST_T::size, and MTGP32_FAST_T::status.
Referenced by mtgp32_genrand_close_open(), and mtgp32_genrand_open_close().
| static float mtgp32_genrand_close_open | ( | mtgp32_fast_t * | mtgp32 | ) | [inline, static] |
This function generates and returns single precision pseudorandom number which distributes uniformly in the range [0, 1).
mtgp32_init(), mtgp32_init_by_array() or mtgp32_init_by_str() must be called before this function.
| [in,out] | mtgp32 | MTGP all in one structure. |
References mtgp32_genrand_close1_open2().
| static float mtgp32_genrand_open_close | ( | mtgp32_fast_t * | mtgp32 | ) | [inline, static] |
This function generates and returns single precision pseudorandom number which distributes uniformly in the range (0, 1].
mtgp32_init(), mtgp32_init_by_array() or mtgp32_init_by_str() must be called before this function.
| [in,out] | mtgp32 | MTGP all in one structure. |
References mtgp32_genrand_close1_open2().
| static float mtgp32_genrand_open_open | ( | mtgp32_fast_t * | mtgp32 | ) | [inline, static] |
This function generates and returns single precision pseudorandom number which distributes uniformly in the range (0, 1).
mtgp32_init(), mtgp32_init_by_array() or mtgp32_init_by_str() must be called before this function.
| [in,out] | mtgp32 | MTGP all in one structure. |
References MTGP32_STATUS_FAST_T::array, MTGP32_PARAMS_FAST_T::flt_tmp_tbl, MTGP32_STATUS_FAST_T::idx, MTGP32_STATUS_FAST_T::large_mask, MTGP32_STATUS_FAST_T::large_size, mtgp32_next_state(), mtgp32_temper_float_open(), MTGP32_FAST_T::params, MTGP32_PARAMS_FAST_T::pos, MTGP32_STATUS_FAST_T::size, and MTGP32_FAST_T::status.
| static uint32_t mtgp32_genrand_uint32 | ( | mtgp32_fast_t * | mtgp32 | ) | [inline, static] |
This function generates and returns 32-bit unsigned integer.
mtgp32_init(), mtgp32_init_by_array() or mtgp32_init_by_str() must be called before this function.
| [in,out] | mtgp32 | MTGP all in one structure. |
References MTGP32_STATUS_FAST_T::array, MTGP32_STATUS_FAST_T::idx, MTGP32_STATUS_FAST_T::large_mask, MTGP32_STATUS_FAST_T::large_size, mtgp32_next_state(), mtgp32_temper(), MTGP32_FAST_T::params, MTGP32_PARAMS_FAST_T::pos, MTGP32_STATUS_FAST_T::size, MTGP32_FAST_T::status, and MTGP32_PARAMS_FAST_T::tmp_tbl.
| int mtgp32_init | ( | mtgp32_fast_t * | mtgp32, | |
| const mtgp32_params_fast_t * | para, | |||
| uint32_t | seed | |||
| ) |
This function allocates and initializes the internal state array with a 32-bit integer seed.
The allocated memory should be freed by calling mtgp32_free(). para should be one of the elements in the parameter table (mtgp32-param-ref.c).
| [out] | mtgp32 | MTGP structure. |
| [in] | para | parameter structure |
| [in] | seed | a 32-bit integer used as the seed. |
References alloc_state(), MTGP32_STATUS_FAST_T::array, MTGP32_STATUS_FAST_T::idx, mtgp32_init_state(), MTGP32_STATUS_FAST_T::size, and MTGP32_FAST_T::status.
| int mtgp32_init_by_array | ( | mtgp32_fast_t * | mtgp32, | |
| const mtgp32_params_fast_t * | para, | |||
| uint32_t * | array, | |||
| int | length | |||
| ) |
This function allocates and initializes the internal state array with a 32-bit integer array.
The allocated memory should be freed by calling mtgp32_free(). para should be one of the elements in the parameter table (mtgp32-param-ref.c).
| [out] | mtgp32 | MTGP structure. |
| [in] | para | parameter structure |
| [in] | array | a 32-bit integer array used as a seed. |
| [in] | length | length of the array. |
References alloc_state(), MTGP32_STATUS_FAST_T::array, MTGP32_STATUS_FAST_T::idx, ini_func1(), ini_func2(), MTGP32_PARAMS_FAST_T::mexp, non_zero, MTGP32_FAST_T::params, MTGP32_STATUS_FAST_T::size, MTGP32_FAST_T::status, and MTGP32_PARAMS_FAST_T::tbl.
| int mtgp32_init_by_str | ( | mtgp32_fast_t * | mtgp32, | |
| const mtgp32_params_fast_t * | para, | |||
| char * | array | |||
| ) |
This function allocates and initializes the internal state array with a character array.
The allocated memory should be freed by calling mtgp32_free(). para should be one of the elements in the parameter table (mtgp32-param-ref.c). This is the same algorithm with mtgp32_init_by_array(), but hope to be more useful.
| [out] | mtgp32 | MTGP structure. |
| [in] | para | parameter structure |
| [in] | array | a character array used as a seed. (terminated by zero.) |
References alloc_state(), MTGP32_STATUS_FAST_T::array, MTGP32_STATUS_FAST_T::idx, ini_func1(), ini_func2(), MTGP32_PARAMS_FAST_T::mexp, non_zero, MTGP32_FAST_T::params, MTGP32_STATUS_FAST_T::size, MTGP32_FAST_T::status, and MTGP32_PARAMS_FAST_T::tbl.
| void mtgp32_init_state | ( | uint32_t | array[], | |
| const mtgp32_params_fast_t * | para, | |||
| uint32_t | seed | |||
| ) |
This function initializes the internal state array with a 32-bit integer seed.
The allocated memory should be freed by calling mtgp32_free(). para should be one of the elements in the parameter table (mtgp32-param-ref.c).
This function is call by cuda program, because cuda program uses another structure and another allocation method.
| [out] | array | MTGP internal status vector. |
| [in] | para | parameter structure |
| [in] | seed | a 32-bit integer used as the seed. |
References MTGP32_PARAMS_FAST_T::mexp, and MTGP32_PARAMS_FAST_T::tbl.
Referenced by make_kernel_data(), and mtgp32_init().
| static void mtgp32_next_state | ( | mtgp32_fast_t * | mtgp32 | ) | [inline, static] |
The state transition function.
| [in,out] | mtgp32 | the all in one structure |
References MTGP32_STATUS_FAST_T::array, MTGP32_STATUS_FAST_T::idx, MTGP32_STATUS_FAST_T::large_mask, MTGP32_STATUS_FAST_T::large_size, MTGP32_PARAMS_FAST_T::mask, mtgp32_do_recursion(), MTGP32_FAST_T::params, MTGP32_PARAMS_FAST_T::pos, MTGP32_PARAMS_FAST_T::sh1, MTGP32_PARAMS_FAST_T::sh2, MTGP32_STATUS_FAST_T::size, MTGP32_FAST_T::status, and MTGP32_PARAMS_FAST_T::tbl.
Referenced by mtgp32_genrand_close1_open2(), mtgp32_genrand_open_open(), and mtgp32_genrand_uint32().
| void mtgp32_print_idstring | ( | const mtgp32_fast_t * | mtgp32, | |
| FILE * | fp | |||
| ) |
This function prints the Mersenne exponent and SHA1 of characteristic polynomial of generators state transition function.
| [in] | mtgp32 | MTGP all in one structure. |
| [in,out] | fp | FILE pointer. |
References MTGP32_PARAMS_FAST_T::mexp, MTGP32_FAST_T::params, and MTGP32_PARAMS_FAST_T::poly_sha1.
| static uint32_t mtgp32_temper | ( | const uint32_t | tmp_tbl[16], | |
| uint32_t | r, | |||
| uint32_t | t | |||
| ) | [inline, static] |
The tempering function.
| [in] | tmp_tbl | the pre-computed tempering table. |
| [in] | r | the value to be tempered. |
| [in] | t | the tempering helper value. |
Referenced by mtgp32_genrand_uint32().
| static float mtgp32_temper_float | ( | const uint32_t | flt_tmp_tbl[16], | |
| uint32_t | r, | |||
| uint32_t | t | |||
| ) | [inline, static] |
The tempering and converting function.
| [in] | flt_tmp_tbl | the pre-computed tempering table. |
| [in] | r | the value to be tempered. |
| [in] | t | the tempering helper value. |
Referenced by mtgp32_genrand_close1_open2().
| static float mtgp32_temper_float_open | ( | const uint32_t | flt_tmp_tbl[16], | |
| uint32_t | r, | |||
| uint32_t | t | |||
| ) | [inline, static] |
The tempering and converting function for generating floating point number f (0 < f < 1).
| [in] | flt_tmp_tbl | the pre-computed tempering table. |
| [in] | r | the value to be tempered. |
| [in] | t | the tempering helper value. |
Referenced by mtgp32_genrand_open_open().
parameter constants tables for MEXP=11213.
size - pos > 256.
parameter constants tables for MEXP=44497.
size - pos > 1024.
1.5.9