The OpenD Programming Language

bernoulli2Variable

$(WIKI_D Bernoulli). A fast specialization for p := 1/2.

import mir.random.variable;
alias bernoulli2Variable = bernoulli2Var

Examples

import mir.random.engine;
auto rv = bernoulli2Var;
static assert(isRandomVariable!(typeof(rv)));
int[2] hist;
foreach(_; 0..1000)
    hist[rv(rne)]++;
import mir.random.engine;
Random* gen = threadLocalPtr!Random;
auto rv = Bernoulli2Variable.init;
int[2] hist;
foreach(_; 0..10)
    hist[rv(gen)]++;

Meta