Phân phối Negative Binomial (Negative Binomial Distribution) là phân phối số ngẫu nhiên tạo ra các số nguyên theo phân phối rời rạc nhị thức âm. Còn gọi là phân phối Pascal. Công thức:
$$P(i|k,p) = \binom{k+i-1}{i} p^k (1-p)^i$$
Ví dụ C++
#include <iostream>
#include <random>
using namespace std;
int main() {
const int nrolls = 10000; // số lần lặp
const int nstars = 100; // số sao tối đa hiển thị
default_random_engine generator;
negative_binomial_distribution<int> distribution(3, 0.5);
int p[10] = {};
for(int i=0; i
Kết quả mẫu
0: ************ 1: ******************* 2: ***************** 3: **************** 4: *********** 5: ******* 6: ***** 7: *** 8: ** 9: *