dgsrand(3C)
_________________________________________________________________
dgsrand function
Specify starting number for the dg_rand and dg_rand1 functions.
_________________________________________________________________
Calling Sequence
int m, dgsrand();
(void) dgsrand(m);
where m is of type int.
Description
Use the dg_srand function to specify a seed for the dg_rand and
dg_rand1 functions; this function is Data General's version of
the srand function. The seed is the number from which random
number generation will begin. If you change the seed for either
dg_rand or dg_rand1, you change it for the other. If you specify
a positive seed, both functions will base the random numbers on
the seed. If you specify a negative or 0 seed, both functions
will use the current time as the seed.
The include file math.h defines this entry.
Returns
The dg_srand function returns the new seed value.
Related Functions
See also the dg_rand, srand, and dg_rand1 functions.
Example
/* Program test for the dg_srand() function */
#include <math.h>
int seed, m, i = 0, c, dg_srand();
short int dg_rand();
main() {
printf("Enter a seed:\n");
scanf("%d", &seed);
dg_srand(seed);
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
dgsrand(3C)
printf("How many numbers?\n");
scanf("%d", &c);
printf("%d random numbers using a seed = %d:\n\n",
c, seed);
while (i < c) {
printf("%d\n", m = dg_rand());
i++;
}
}
A call to the program test with entries 13 and 4 generates the
output
4 random numbers using a seed = 13:
13338
2308
17310
17096
These numbers will vary.
DG/UX 4.00 Page 2
Licensed material--property of copyright holder(s)