Retrieves the current value of the seed used in the random number generators.
#include <imsls.h>
int imsls_random_seed_get ( )
The value of the seed.
Function imsls_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 function imsls_random_seed_set to reset the seed.
This example illustrates the statements required to restart a simulation using imsls_random_seed_get and imsls_random_seed_set. 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 <imsls.h>
#define N_RANDOM 5
int main()
{
int seed = 123457;
float *r1, *r2, *r;
imsls_random_seed_set(seed);
r1 = imsls_f_random_uniform(N_RANDOM, 0);
imsls_f_write_matrix ("First Group of Random Numbers", 1,
N_RANDOM, r1, 0);
seed = imsls_random_seed_get();
imsls_random_seed_set(seed);
r2 = imsls_f_random_uniform(N_RANDOM, 0);
imsls_f_write_matrix ("Second Group of Random Numbers", 1,
N_RANDOM, r2, 0);
imsls_random_seed_set(123457);
r = imsls_f_random_uniform(2*N_RANDOM, 0);
imsls_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 |