When I use this rand()
function, i always get the same number even though i put srand(time(NULL))
at the start of my main program. Here is an example
int main() {
//declerations...
srand(time(NULL));
for(something) {
int r1 = rand() % 101;
int r2 = rand() % 101;
printf("CLIENT PID: %d\n", getpid());
Client(r1, r2);
}
return 0;
}
Client is a simple function that does an operation. Example code right here:
void Client(int r1, int r2) {
int result = r1 * r2;
printf("Here is the product: %d\n", result);
}
Here's an output example:
value1: 67
value2: 31
value1: 67
value2: 31
value1: 67
value2: 31
.
.
.
Now since i called the rand()
in the loop i should be getting always different numbers, but why isn't this happening?
Aucun commentaire:
Enregistrer un commentaire