The OpenD Programming Language

binomialVar

$(WIKI_D Binomial).

binomialVar
(
T
)
(
size_t r
,
in T p
)

Examples

import mir.random;
auto rv = binomialVar(20, 0.5);
static assert(isRandomVariable!(typeof(rv)));
int[] hist = new int[rv.max + 1];
auto cnt = 1000;
foreach(_; 0..cnt)
    hist[rv(rne)]++;
//import std.stdio;
//foreach(n, e; hist)
//    writefln("p(x = %s) = %s", n, double(e) / cnt);
import mir.random.engine;
Random* gen = threadLocalPtr!Random;
auto rv = BinomialVariable!double(20, 0.5);
int[] hist = new int[rv.max + 1];
auto cnt = 10;
foreach(_; 0..cnt)
    hist[rv(gen)]++;

Meta