I have a problem with the small game that I made.
#include \"stdafx.h\"
#include
#include
#include
using namespace
There are a number of problems with rand()
. You've run into one of them, which is that the first several values aren't "random". If you must use rand()
, it is always a good idea to discard the first four or results from rand()
.
srand (time(0));
rand();
rand();
rand();
rand();
Another problem with rand()
is that the low order bits are notoriously non-random, even after the above hack. On some systems, the lowest order bit alternates 0,1,0,1,0,1,... It's always better to use the high order bits such as by using the quotient rather than the remainder.
Other problems: Non-randomness (most implementations of rand()
fails a number of tests of randomness) and short cycle. With all these problems, the best advice is to use anything but rand()
.