mirror of
https://github.com/kuhyx/testsAndMisc-archive.git
synced 2026-07-04 15:23:06 +02:00
23 lines
494 B
C++
Executable File
23 lines
494 B
C++
Executable File
// bernoulli_distribution
|
|
#include <iostream>
|
|
#include <random>
|
|
|
|
int main()
|
|
{
|
|
const int nrolls=10000;
|
|
|
|
std::random_device rd;
|
|
std::mt19937 gen(rd());
|
|
std::bernoulli_distribution distribution(0.5);
|
|
|
|
int count=0; // count number of trues
|
|
|
|
for (int i=0; i<nrolls; ++i) if (distribution(gen)) ++count;
|
|
|
|
std::cout << "bernoulli_distribution (0.5) x 10000:" << std::endl;
|
|
std::cout << "true: " << count << std::endl;
|
|
std::cout << "false: " << nrolls-count << std::endl;
|
|
|
|
return 0;
|
|
}
|