This question already has an answer here:
- srand() — why call it only once? 7 answers
While creating 2 different random numbers, they are the same as each other every time.
void foo() {
int YPos;
int XPos;
YPos = ranInt();
cout << YPos << endl;
XPos = ranInt();
cout << XPos << endl;
}
int ranInt() {
srand(time(NULL));
int ranNum;
ranNum = rand() % 4 + 1;
return ranNum - 1;
}
This gives me an example output:
2
2
How would I go about making these numbers different from each other?
Aucun commentaire:
Enregistrer un commentaire