I'm using srand()
to generate numbers from 0 to 3. My output is repeating the same combination of the four numbers and I'm not sure why or how to fix it.
#include <iostream>
int main(int argc, char** argv) {
srand((unsigned int) time(NULL));
for(int i = 0; i < 20; i++) {
int n = std::rand() % 4;
std::cout << n;
}
std::cout << std::endl;
return 0;
}
Code output:
C:\School\ProgFund3\Int Stack>a
12301230123012301230
C:\School\ProgFund3\Int Stack>a
23012301230123012301
C:\School\ProgFund3\Int Stack>a
30123012301230123012
C:\School\ProgFund3\Int Stack>