Chapter 12: Random Number Generation > random_GFSR_table_get

random_GFSR_table_get

Retrieves the current table used in the GFSR generator.

Synopsis

#include <imsls.h>

void imsls_random_GFSR_table_get (int **table, ..., 0)

Required Arguments

int **table   (Output)
Address of a pointer to an array of length 1565 containing the table used in the  GFSR generators.  Typically, int *table is  declared and &table is used as an argument.

Synopsis with Optional Arguments

#include <imsls.h>

void imsls_random_GFSR_table_get (int **table,
IMSLS_RETURN_USER, int r[],
 0)

Optional Arguments

IMSLS_RETURN_USER, int r[]   (Output)
User-supplied array of length 1565 containing the table used in the GFSR generators.

Description

The values in table are initialized by the IMSL random number generators. The values are all positive except if the user wishes to reinitialize the array, in which case the first element of the array is input as a nonpositive value. (Usually, one should avoid reinitializing these arrays, but it might be necessary sometimes in restarting a simulation.) If the first element of table is set to a nonpositive value on the call to imsls_random_GFSR_table_set, on the next invocation of a routine to generate random numbers using a GFSR method, the appropriate array will be reinitialized.

Example

In this example, three separate simulation streams are used, each with a different form of the generator. Each stream is stopped and restarted. (Although this example is obviously an artificial one, there may be reasons for maintaining separate streams and stopping and restarting them because of the nature of the usage of the random numbers coming from the separate streams.)

 

#include <stdio.h>

#include <imsls.h>

 

int main()

{

  float *r, *table;

  int  nr, iseed1, iseed2, iseed7;

  int *itable;

 

  nr = 5;

  iseed1 = 123457;

  iseed2 = 123457;

  iseed7 = 123457;

 

  /* Begin first stream, iopt = 1 (by default) */

  imsls_random_seed_set (iseed1);

  r = imsls_f_random_uniform (nr, 0);

  iseed1 = imsls_random_seed_get ();

  imsls_f_write_matrix ("First stream output", 1, 5, r,

                 IMSLS_NO_COL_LABELS,

                 IMSLS_NO_ROW_LABELS, 0);

  printf("    Output seed\t%d\n\n", iseed1);

  free(r);

 

  /* Begin second stream, iopt = 2 */

  imsls_random_option (2);

  imsls_random_seed_set (iseed2);

  r = imsls_f_random_uniform (nr, 0);

  iseed2 = imsls_random_seed_get ();

  imsls_f_random_table_get (&table, 0);

  imsls_f_write_matrix ("Second stream output", 1, 5, r,

                 IMSLS_NO_COL_LABELS,

                 IMSLS_NO_ROW_LABELS, 0);

  printf("    Output seed\t%d\n\n", iseed2);

  free(r);

 

  /* Begin third stream, iopt = 7 */

  imsls_random_option (7);

  imsls_random_seed_set (iseed7);

  r = imsls_f_random_uniform (nr, 0);

  iseed7 = imsls_random_seed_get ();

  imsls_random_GFSR_table_get (&itable, 0);

  imsls_f_write_matrix ("Third stream output", 1, 5, r,

                 IMSLS_NO_COL_LABELS,

                 IMSLS_NO_ROW_LABELS, 0);

  printf("    Output seed\t%d\n\n", iseed7);

  free(r);

 

  /* Reinitialize seed and resume first stream */

  imsls_random_option (1);

  imsls_random_seed_set (iseed1);

  r = imsls_f_random_uniform (nr, 0);

  iseed1 = imsls_random_seed_get ();

  imsls_f_write_matrix ("First stream output", 1, 5, r,

                 IMSLS_NO_COL_LABELS,

                 IMSLS_NO_ROW_LABELS, 0);

  printf("    Output seed\t%d\n\n", iseed1);

  free(r);

 

  /*

   * Reinitialize seed and table for shuffling and

   * resume second stream

   */

  imsls_random_option (2);

  imsls_random_seed_set (iseed2);

  imsls_f_random_table_set (table);

  r = imsls_f_random_uniform (nr, 0);

  iseed2 = imsls_random_seed_get ();

  imsls_f_write_matrix ("Second stream output", 1, 5, r,

                 IMSLS_NO_COL_LABELS,

                 IMSLS_NO_ROW_LABELS, 0);

  printf("    Output seed\t%d\n\n", iseed2);

  free(r);

 

  /*

   * Reinitialize seed and table for GFSR and

   * resume third stream.

   */

  imsls_random_option (7);

  imsls_random_seed_set (iseed7);

  imsls_random_GFSR_table_set (itable);

  r = imsls_f_random_uniform (nr, 0);

  iseed7 = imsls_random_seed_get ();

  imsls_f_write_matrix ("Third stream output", 1, 5, r,

                 IMSLS_NO_COL_LABELS,

                 IMSLS_NO_ROW_LABELS, 0);

  printf("    Output seed\t%d\n\n", iseed7);

  free(r);

 

}

 Output

 

                    First stream output

    0.9662      0.2607      0.7663      0.5693      0.8448

 Output seed     1814256879

 

 

                   Second stream output

    0.7095      0.1861      0.4794      0.6038      0.3790

 Output seed     1965912801

 

 

                    Third stream output

    0.3914      0.0263      0.7622      0.0281      0.8997

 Output seed     1932158269

 

 

                    First stream output

    0.0443      0.9872      0.6014      0.8964      0.3809

 Output seed     817878095

 

 

                   Second stream output

    0.2557      0.4788      0.2258      0.3455      0.5811

 Output seed     2108806573

 

 

                    Third stream output

    0.7519      0.5084      0.9070      0.0910      0.6917

 Output seed     1485334679


RW_logo.jpg
Contact Support