srand()与rand()生成随机数
srand()与rand()生成随机数
经过测试,当srand的值确定时,其对应的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; } }