码迷,mamicode.com
首页 > 编程语言 > 详细

C++产生随机数示例

时间:2014-06-08 17:26:30      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:c   class   blog   code   a   int   

#include <iostream>
#include <cstdlib>
#include <ctime>
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;
}


 

C++产生随机数示例,布布扣,bubuko.com

C++产生随机数示例

标签:c   class   blog   code   a   int   

原文地址:http://blog.csdn.net/u010142437/article/details/28882499

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!