生成随机数模板

#include <bits/stdc++.h>
using namespace std;

int bak[10000];

int main () {
	mt19937 e (time (0));
	uniform_int_distribution <int> u (-10, 10);//均匀 int
//	uniform_real_distribution <double> u (-10, 10);//均匀 double
//	bernoulli_distribution u(0.5); // 可控 0 / 1 比例的 01 生成器
//	binomial_distribution <int> u; // 二向 01 生成器
	for (int i = 1; i <= 10000000; i++) {
		int tmp = u (e); 
//		cout << tmp << " ";
		bak[tmp + 10]++;
	}
	for (int i = -10; i <= 10; i++) {
		printf ("bak[%d] = %d\n", i, bak[i + 10]);
	}
	cout << endl;
	
	cout << e (); // 生成随机数
	
	vector <int> a;
	shuffle (a.begin (), a.end (), e); // 打乱顺序
	return 0;
}
posted @ 2022-05-26 15:59  C2022lihan  阅读(12)  评论(0编辑  收藏  举报