How to..?

Hello guys, I have this code which generates and prints out numbers from 0 to 2. The problem is, that for some reason there is no "00" combination... The other combinations work perfectly! 01,02,10,11,12,20,21,22. How to make such that the program generates "00" as well. Thanks

#include <conio.h>
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{

int p, q;


for (int i=0; i<1000000; i++)
{
srand((unsigned)time(NULL));
p = (rand()%3);
q = (rand()%3);
cout<<p; cout<<q<<endl;

}

getch();
return 1;
}



Last edited on
@nick9449

Try moving srand((unsigned)time(NULL)); to before the for loop. With it inside the loop, you don't get a variety of random numbers because the srand starts reading the first number using the time seed. After changing it, I ran it with with just 100 numbers, and got plenty of 00.
Topic archived. No new replies allowed.