std::binomial_distribution
Min standard notice:
Header: <random>
Produces random non-negative integer values i, distributed according to discrete probability function:
# Declarations
template< class IntType = int >
class binomial_distribution;
(since C++11)
# Example
#include <iomanip>
#include <iostream>
#include <map>
#include <random>
#include <string>
int main()
{
std::random_device rd;
std::mt19937 gen(rd());
// perform 4 trials, each succeeds 1 in 2 times
std::binomial_distribution<> d(4, 0.5);
std::map<int, int> hist;
for (int n = 0; n != 10000; ++n)
++hist[d(gen)];
for (auto const& [x, y] : hist)
std::cout << x << ' ' << std::string(y / 100, '*') << '\n';
}