Retrieves the current table used in the 32-bit Mersenne Twister generator.
#include <imsls.h>
void imsls_random_MT32_table_get (unsigned int **table, ..., 0)
unsigned int **table (Output)
Address of a
pointer to an array of length 625 containing the table used in the 32-bit
Mersenne Twister generator. Typically,
unsigned int *table is declared and
&table is
used as an argument.
#include <imsls.h>
void
imsls_random_MT32_table_get (int **table,
IMSLS_RETURN_USER, int r[],
0)
IMSLS_RETURN_USER,
int r[]
(Output)
User-supplied array of length 625 containing the table used in the
32-bit Mersenne Twister generator.
The values in table contain the state of the 32-bit Mersenne Twister random number generator. The table can be used by imsls_random_MT32_table_set to set the generator back to this state.
In this example, four simulation streams are generated. The first series is generated with the seed used for initialization. The second series is generated using an array for initialization. The third series is obtained by resetting the generator back to the state it had at the beginning of the second stream. Therefore, the second and third streams are identical. The fourth stream is obtained by resetting the generator back to its original, uninitialized state, and having it reinitialize using the seed. The fourth and first streams are therefore the same.
#include <imsls.h>
int main()
{
const unsigned int init[] = {0x123, 0x234, 0x345, 0x456};
float *r;
int iseed = 123457;
int *itable;
int nr = 5;
/* Initialize Mersenne Twister series with a seed */
imsls_random_option (8);
imsls_random_seed_set (iseed);
r = imsls_f_random_uniform (nr, 0);
imsls_f_write_matrix ("First stream output", 1, 5, r,
IMSLS_NO_COL_LABELS,
IMSLS_NO_ROW_LABELS,
0);
free(r);
/* Reinitialize Mersenne Twister series with an array */
imsls_random_option (8);
imsls_random_MT32_init(4, init);
/* Save the state of the series */
imsls_random_MT32_table_get(&itable, 0);
r = imsls_f_random_uniform (nr, 0);
imsls_f_write_matrix ("Second stream output", 1, 5, r,
IMSLS_NO_COL_LABELS,
IMSLS_NO_ROW_LABELS,
0);
free(r);
/* Restore the state of the series */
imsls_random_MT32_table_set(itable);
r = imsls_f_random_uniform (nr, 0);
imsls_f_write_matrix ("Third stream output", 1, 5, r,
IMSLS_NO_COL_LABELS,
IMSLS_NO_ROW_LABELS,
0);
free(r);
/* Reset the series - it will reinitialize from the seed */
itable[0] = 1000;
imsls_random_MT32_table_set(itable);
r = imsls_f_random_uniform (nr, 0);
imsls_f_write_matrix ("Fourth stream output", 1, 5, r,
IMSLS_NO_COL_LABELS,
IMSLS_NO_ROW_LABELS,
0);
free(r);
}
First stream output
0.4347 0.3522 0.0139 0.2091 0.4956
Second stream output
0.2486 0.2226 0.1111 0.9563 0.9846
Third stream output
0.2486 0.2226 0.1111 0.9563 0.9846
Fourth stream output
0.4347 0.3522 0.0139 0.2091 0.4956