Phân phối Bernoulli (Bernoulli Distribution) là phân phối rời rạc có hai kết quả: x=0 (thất bại) và x=1 (thành công). Xác suất thành công p, thất bại q = 1-p.
$$P(x) = \begin{cases} 1-p & \text{cho } x=0 \\ p & \text{cho } x=1 \end{cases}$$
Cũng có thể viết: $$P(x) = p^x (1-p)^{1-x}$$
Ví dụ C++
#include <iostream>
#include <random>
using namespace std;
int main() {
const int nrolls = 10000;
default_random_engine generator;
bernoulli_distribution distribution(0.7);
int count = 0; // đếm số true
for(int i=0; i
Kết quả mẫu
bernoulli_distribution (0.7) x 10000: true: 7024 false: 2976