Keep in mind srand () do not call two times or more than two times.
void Main ()
{
for (int i=0;i<10;i++)
{
Srand ((unsigned) time (NULL));
Cout<<rand () <<endl;
}
}
When this is called, the Srand ((unsigned) time (NULL) is invoked because of the high speed relationship of the CPU; The number of seeds generated. Causes rand () to produce random numbers as well.
To
void Main ()
{srand (unsigned) time (NULL));
for (int i=0;i<10;i++)
{
Cout<<rand () <<endl;
}
}
Sometimes these errors are hidden and a check method is made in the constructor. Call the Init method in the check method, and then generate a random number in the Init method. Note If Srand ((unsigned) time (NULL)); is written in a check () or init () method, make sure that the method is only invoked once at construction time. It is best to put the line code Srand ((unsigned) time (NULL)), and write to the constructor to initialize the seed.