বার্নোলি ডিস্ট্রিবিউশন হল একটি বিচ্ছিন্ন ডিস্ট্রিবিউশন যার দুটি সম্ভাব্য ফলাফলকে x =0 এবং x =1 দ্বারা লেবেল করা হয়েছে। x =1 হল সাফল্য, এবং x =0 হল ব্যর্থতা। সফলতা ঘটবে সম্ভাবনা p এর সাথে, এবং ব্যর্থতা ঘটবে সম্ভাবনা q এর সাথে q =1 – p হিসাবে। তাই
$$P\lgroup x\rgroup=\begin{cases}1-p\:for &x =0\\p\:for &x =0\end{cases}$$
এটিকে −
হিসেবেও লেখা যেতে পারে$$P\lgroup x\rgroup=p^{n}\lgroup1-p\rgroup^{1-n}$$
উদাহরণ
#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; // count number of trues
for (int i=0; i<nrolls; ++i)
if (distribution(generator))
count++;
cout << "bernoulli_distribution (0.7) x 10000:" << endl;
cout << "true: " << count << endl;
cout << "false: " << nrolls-count << endl;
} আউটপুট
bernoulli_distribution (0.7) x 10000: true:7024 false: 2976