The following code is a lab that I have completed for class. I am new to C++ and am learning along the way so please be gentle if I am overlooking something that seems pretty obvious. I created a main funtion, a make board function, and a print board function for a Bingo game. Here is the code
system("pause");
return 0;
}
The program compiles and the Bingo board is printed out 3 times as desired. The numbers on each iteration of the Bingo board are the same. How do I generate different numbers on each iteration of the Bingo board?
Make sure you're not including the call to srand() inside the loop. Doing so will cause the RNG to be seeded with the same number each time srand() is called.
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Do you mean you run the program three times? time(0) returns the time in seconds so if you run the program within the same second the same number will be passed to srand, which means rand() will give you the same sequence of numbers, which means you get the same bingo board. A solution to this problem could be to wait a bit longer between running the program, or you could use a different seed that is more likely to be different each time the program runs.