From the documentation of rand:
There are no guarantees as to the quality of the random sequence produced. In the past, some implementations of rand() have had serious shortcomings in the randomness, distribution and period of the sequence produced (in one well-known example, the low-order bit simply alternated between 1 and 0 between calls). rand() is not recommended for serious random-number generation needs. It is recommended to use C++11's random number generation facilities to replace rand().
It (and I) recommend to use the newer c++11 random number generators in <random>.
In your specific case it seems you want a std::uniform_int_distribution. An example, as given on the linked page is:
std::random_device rd; //Will be used to obtain a seed for the random number engine std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd() std::uniform_int_distribution<> distrib(1, RAND_MAX); std::cout << distrib(gen) << '\n';
<random>instead. And fyi, if you did userandandsrandyou should#include <cstdlib>, as the standard library mandates that header for access to those functions.time()has seconds precision, so if those 5 runs are close together, you will be seeding the RNG with very similar starting values. You should not be using the Crand()RNG in C++ to begin with, use C++ RNGs from the<random>library instead.