对于随机数的产生,涉及到两个函数:rand() 与 srand()
如下例子:
#include<iostream> #include<ctime> #include<cstdlib> using namespace std; int main() { srand( (unsigned)time(NULL) ); //设置种子 cout << rand() << endl; //生成随机数 return 0; }