i have following program:
srand((unsigned) time(NULL));
for (int w = 0; w < 10; w++) {
int ran_x;
ran_x = rand() % 255;
cout << "nRandom X = " << ran_x << endl;
//some more lines of code
Sleep(1000);
}
I am running it on visual c++ 2008, When I run this program, it doesnt show any errors or warnings. But when I run it, some of the times it runs fine, and some of the times it stops in the middle and gives this error "This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information."
What shall I do? Is it possible to do it with out using Sleep() function and still get randomly generated values. Because if I remove Sleep(1000), it doesnt give any error but it doesnt gives random values either
What's the content of "some more lines of code"?
<psychic debugging>I bet you have code that there that, directly or indirectly, depends on the random value you generated earlier. This code will likely be a division, or involve setting the length of some container, and borks when the generated random number is 0.</psychic debugging>