我是靠谱客的博主 鲜艳蜗牛,这篇文章主要介绍【基础】随机数生成--C++源代码(VS2015),现在分享给大家,希望可以做个参考。

#include <iostream>
#include <ctime>
#include <vector>
using namespace std;

void Print(const vector<int> &vec)
{
for (vector<int>::const_iterator iter = vec.begin(); iter != vec.end(); iter++)
cout << *iter << " ";
cout << endl;
}

int main()
{
/* 设置rand()产生随机数时的随机数种子
time(0)或者time(NULL)返回的是系统的时间
(从1970.1.1午夜算起),单位:秒 */
srand(time(NULL));
vector<int> vec;
for (int i = 0;i<10;i++)
{
vec.push_back(rand() % 100);
}
Print(vec);
system("pause");
return 0;
}

最后

以上就是鲜艳蜗牛最近收集整理的关于【基础】随机数生成--C++源代码(VS2015)的全部内容,更多相关【基础】随机数生成--C++源代码(VS2015)内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(55)

评论列表共有 0 条评论

立即
投稿
返回
顶部