https://www.tqwba.com/x_d/jishu/23220.html
std::discrete_distribution<size_t> d{1, 1, 1, 1, 1, 3}/ // Six possible values std::random_device rd;
std::default_random_engine rng {rd()};
std::map<size_t, size_t> results; // Store the results of throws
for(size_t go {}; go < 5000; ++go) // 5000 throws of the die
++results[d(rng)];
for(const auto& pr : results)
std::cout << "A" << (pr.first+1) << " was thrown " << pr.second << " times\n";
#include<iostream>
#include<random>
int arr[100];
//priority 按照权重分布产生随机数
std::random_device rd;
std::discrete_distribution<size_t> d{ 1, 2, 2, 30, 20 };// Six possible values std::random_device rd;
std::default_random_engine rng{ rd() };
//std::map<size_t, size_t> results; // Store the results of throws
for (int i = 0; i < 100; i++) {
arr[i] = d(rng);
std::cout << "arr[" << i << "] = " <<arr[i] << "\n";
}
//for (size_t go{}; go < 100; ++go) // 5000 throws of the die
// ++results[d(rng)];
//for (const auto& pr : results)
// std::cout << "A" << (pr.first + 1) << " was thrown " << pr.second << " times\n";