srand ( ) and rand ( )
#include <stdio.h> Since we are always
#include <stdlib.h> using the value 67
#define SEED 67 generator, the same numbers will be
main ( ) produced whenever we run our
{ program
int i, num;
srand (SEED);
for (i = 0; i < 5; i++)
{
num = rand ( );
num = 1 + num % 6;
printf (“%d\n”, num);
}
}
Previous slide
Next slide
Back to first slide
View graphic version