Same random numbers every time I run the program

You need to give the randum number generator a seed. This can be done by taking the current time, as this is hopefully some kind of random.

#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{
    int  r;
    srand(time(0));
    r = rand();
    return 0;
} 

You need to seed your random number generator:

Try putting this at the beginning of the program:

srand ( time(NULL) );

Note that you will need to #include <ctime>.

The idea here is to seed the RNG with a different number each time you launch the program. By using time as the seed, you get a different number each time you launch the program.

Tags:

C++

Random