Your question is slightly unclear but I think your problem is that you are expecting different random numbers each time you run your program. Note that rand() will generate the same sequence of random numbers every time you run your program unless you provide it with some sort of seed value.
The standard way to do this is to use the current time to seed the random number generator, as below.
#include <iostream>
#include <ctime>
#include <cstdlib>
int main() {
srand(time(NULL));
std::cout << rand();
return 0;
}
This will produce a different random sequence each time. If you were to remove the srand(time(NULL)) line, you would get the same result every time you ran the program.
You only need to call srand(time(NULL)) once at the start of your program.
EDIT: I'm just also going to edit my post to mention that there is a dedicated 'random' header in C++11, I haven't used this yet so I can't comment much on it, but you can read about it here