srand(3C)
_________________________________________________________________
srand function
Specify a number from which to start random number generation.
_________________________________________________________________
Calling Sequence
int m;
srand(m);
where m is of type int.
Description
Use the srand function to specify a seed to be used for the rand
function. The seed is the number from which random number
generation will begin.
The include file math.h defines this entry.
Returns
The srand function returns the new seed value.
Related Functions
See also the rand and dg_rand functions.
Example
/* Program test for the srand() function */
#include <math.h>
int seed, m, i = 0, c;
main() {
printf("Enter a seed:\n");
scanf("%d", &seed);
srand(seed);
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 = rand());
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
srand(3C)
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)