srand () with rand () generates a random number
After the test, when the value of srand determined, the corresponding values are determined of the rand.
#include <iostream> using namespace std; int main() { for (int i = 0; i <= 10; i++) { srand(i); cout << "当seed = " << i << "时,其结果为:" << rand() << endl; } cout << endl << endl << "------第二次验证---------" << endl << endl; for (int i = 0; i <= 10; i++) { srand(i); cout << "当seed = " << i << "时,其结果为:" << rand() << endl; } }