随机打乱一个数组
// shuffle algorithm example
#include <bits/stdc++.h>
using namespace std;
int main()
{
//freopen("data.out", "w", stdout);
vector<int> foo(5);
for(int i=0;i<5;i++)
foo[i] = i;
unsigned seed = chrono::system_clock::now().time_since_epoch().count();
shuffle(foo.begin(), foo.end(),default_random_engine(seed));
cout << "shuffled elements:";
for (int &x : foo)
cout << ' ' << x;
cout << '\n';
return 0;
}
随机选择
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int i=uniform_int_distribution<int>(1,n)(rng),j=uniform_int_distribution<int>(1,n)(rng); //[1,n]
uniform_real_distribution<double>(1,10000)(rng)