I am relative new to c and c++. In java, the language I am used to program in, its very easy to implement random number generation. Just call the the static random-method fr
The seed is needed for pseudo random number generator to generate different random number sequence from previous ones (not always). If you do not want the repeated sequence then you need to seed the pseudo random number generator.
Try these codes and see the difference.
Without seed:
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("%d", rand()%6 + 1);
}
With seed:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
srand(time(NULL));
printf("%d", rand()%6 + 1);
}