Hello, everyone! I'm having a problem with the following program: I try to call the same function that generates random integers and sends it back to main() (I'm doing that because I wanna apply it to a bigger situation), but the random integers obtained are always the same, why is it happening? Thanks in advance!
Code:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <math.h>
/* Function prototype: */
int generate(void);
int main(void)
{
printf("%d\n\n", generate());
printf("%d\n\n", generate());
printf("%d\n\n", generate());
return 0;
}
int generate(void)
{
int x;
srand(time(NULL));
x = - 100 + rand() % 201;
return x;
}