Retrieves the current value of the seed used in the IMSL random number generators.
#include <imsl.h>
int imsl_random_seed_get ( )
The value of the seed.
The function imsl_random_seed_get retrieves the current value of the “seed” used in the random number generators. A reason for doing this would be to restart a simulation, using imsl_random_seed_set to reset the seed.
This example illustrates the statements required to restart a simulation using imsl_random_seed_get and imsl_random_seed_set. Also, the example shows that restarting the sequence of random numbers at the value of the seed last generated is the same as generating the random numbers all at once.
#include
<imsl.h>
#define
N_RANDOM 5
main()
{
int seed =
123457;
float *r1,
*r2, *r;
imsl_random_seed_set(seed);
r1 =
imsl_f_random_uniform(N_RANDOM, 0);
imsl_f_write_matrix
("First Group of Random Numbers", 1,
N_RANDOM, r1, 0);
seed =
imsl_random_seed_get();
imsl_random_seed_set(seed);
r2 =
imsl_f_random_uniform(N_RANDOM, 0);
imsl_f_write_matrix
("Second Group of Random Numbers", 1,
N_RANDOM, r2, 0);
imsl_random_seed_set(123457);
r =
imsl_f_random_uniform(2*N_RANDOM, 0);
imsl_f_write_matrix
("Both Groups of Random Numbers", 1,
2*N_RANDOM, r, 0);
}
First Group of Random Numbers
1
2
3
4
5
0.9662 0.2607
0.7663 0.5693
0.8448
Second Group of Random Numbers
1
2
3
4
5
0.0443 0.9872
0.6014 0.8964
0.3809
Both Groups of Random Numbers
1
2
3
4
5
6
0.9662 0.2607
0.7663 0.5693
0.8448
0.0443
7
8
9
10
0.9872 0.6014
0.8964 0.3809
|
Visual Numerics, Inc. PHONE: 713.784.3131 FAX:713.781.9260 |