Chapter 12: Random Number Generation

random_MT64_table_get

Retrieves the current table used in the 64-bit Mersenne Twister generator.

Synopsis

#include <imsls.h>

void imsls_random_MT64_table_get (unsigned long long **table, ..., 0)

Required Arguments

unsigned long long **table (Output)
Address of a pointer to an array of length 625 containing the table used in the 64-bit Mersenne Twister generator. Typically, unsigned long long *table is declared and &table is used as an argument.

Synopsis with Optional Arguments

#include <imsls.h>

void imsls_random_MT64_table_get (unsigned long long **table,
IMSLS_RETURN_USER, unsigned long long r[],
0)

Optional Arguments

IMSLS_RETURN_USER, unsigned long long r[] (Output)

User-supplied array of length 625 containing the table used in the 64-bit Mersenne Twister generator.

Description

The values in the table contain the state of the 64-bit Mersenne Twister random number generator. The table can be used by imsls_random_MT64_table_set to set the generator back to this state.

Example

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 long long init[] = {0x123, 0x234, 0x345, 0x456};

       float   *r;

       int     iseed = 123457;

       unsigned long long *itable;

       int     nr = 5;

 

       /* Initialize 64-bit Mersenne Twister series with a seed */

       imsls_random_option (9);

       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 (9);

       imsls_random_MT64_init(4, init);

       /* Save the state of the series */

       imsls_random_MT64_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_MT64_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_MT64_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);

}

 

Output

 

                      First stream output

     0.5799       0.9401       0.7102       0.1640       0.5457

 

                     Second stream output

     0.4894       0.7397       0.5725       0.0863       0.7588

 

                      Third stream output

     0.4894       0.7397       0.5725       0.0863       0.7588

 

                     Fourth stream output

     0.5799       0.9401       0.7102       0.1640       0.5457


Visual Numerics, Inc.
Visual Numerics - Developers of IMSL and PV-WAVE
http://www.vni.com/
PHONE: 713.784.3131
FAX:713.781.9260