跳到正文

闲话

使用random造数据

Percyyy约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年11月15日
收录
2026年4月27日
更新
2026年11月18日
篇幅
约 1 分钟

版本

  1. v1当前
C++
#include <random>
#include <iostream>
using namespace std;
int main() {
    random_device rd;
    mt19937 gen(rd());
    uniform_int_distribution<> dis(1, 1000);
    uniform_int_distribution<> dis_1(1, 100);
    int r = dis(gen);
    cout<<r<<"\n";
    for(int i=1;i<=r;i++){
		for(int j=1;j<=i;j++){
			int s=dis_1(gen);
			cout<<s<<" ";
		}
		cout<<"\n";
    }
   return 0;
}

比 rand()rand() 更好了。

原文