I am trying to store a single random number from 0 to 99 to a variable.
This is what I used in my code to do that:
time_t t;
time(&t);
srand((unsigned int)t);
int rTSB(rand() % 100);
I am trying to make a single random picture show up when you start the program.
However, when I minimize and maximize the window, my picture changes, which is not supposed to happen. Also, when I move my window off the screen and back, part of the picture is the old one and the other part that went off the screen became the other picture.
The code for the picture is something like:
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
if (rTSB >= 0 && rTSB < 35) {
//code to display picture
} else if (rTSB >= 35 && rTSB < 45) {
//code to display another picture
}
and so on . . .
I am thinking that the program loops and a new number gets stored to rTSB every second.
How I do just store one variable and stop the loop? How do I prevent rTSB from having a different value?