This is because Random
is not really random. It is a rather a pseudo random which depends on the seed.
For one random seed, you have one exact set of pseudo random sequence. That's why you get the same result every time you run the program because once compiled, the random seed doesn't change.
In order to make your application having random like behavior every time you run it, consider of using time info as random seed:
#include <cstdlib.h>
#include <time.h>
....
srand (time(NULL)); //somewhere in the initialization
time(NULL)
is the random seed which will change according to the system time you run your application. Then you could use your rand()
with different random seed everytime:
//somewhere else after initialization
char a = 97 + rand() % 26;
char b = 97 + rand() % 26;
char c = 97 + rand() % 26;
char d = 97 + rand() % 26;
char e = 97 + rand() % 26;
char f = 97 + rand() % 26;