C++产生随机数示例

2014-11-23 22:59:22 · 作者: · 浏览: 11

C++产生随机数示例


#include
#include
#include
using std::cout;
using std::endl;
int main(void){

//使用默认种子值产生随机数,每次产生的都一样

cout << rand() << " " << rand() << " " << rand() << endl;

//使用新种子产生随机数,每次都不一样
srand((unsigned int)time(0));
cout << rand() << " " << rand() << " " << rand() << endl;
return 0;
}