The OpenD Programming Language

BinomialVariable

$(WIKI_D Binomial).

struct BinomialVariable (
T
) if (
isFloatingPoint!T
) {
size_t n;
T np;
T q;
T qn;
T r;
T g;
T b;
T a;
T c;
T vr;
T alpha;
T lpq;
T fm;
T h;
bool swap;
}

Constructors

this
this(size_t n, T p)

Members

Functions

max
size_t max()
opCall
size_t opCall(RNG gen)
opCall
size_t opCall(RNG* gen)

Manifest constants

isRandomVariable
enum isRandomVariable;

Variables

min
enum size_t min;

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