我是靠谱客的博主 生动橘子,这篇文章主要介绍用srand时间数种子来生成随机数,现在分享给大家,希望可以做个参考。

没有废话直接上代码

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

int main(){
    srand(unsigned(time(0)));//时间种子
    vector<int> ivec;
    int count = 0;

    for (int i = 0; i < 10000; ++i){
        ivec.push_back(rand() % 10000);//随机数是0~9999的
    }
    for (int i = 0; i < 10000; ++i){
        cout << setw(5) << ivec[i];//设置每个字输出时宽度为5
        ++count;
        if (count == 10){//每10个数就换行
            cout << endl;
            count = 0;
        }
    }
    cout << endl;

    return 0;
}

最后

以上就是生动橘子最近收集整理的关于用srand时间数种子来生成随机数的全部内容,更多相关用srand时间数种子来生成随机数内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部