LibRan  0.1
Pseudo-random number distribution generator
Functions
LRbinom.c File Reference

The Binomial distribution with probability of success p > 0 and n independent tests. More...

#include <math.h>
#include "libran.h"
Include dependency graph for LRbinom.c:

Go to the source code of this file.

Functions

int LRi_binomial_RAN (LR_obj *o)
 LRi_binomial_RAN(LR_obj *o) - int Binomial distributed variate. Default values: probability of success p = 1/2. More...
 
float LRi_binomial_PDF (LR_obj *o, int k)
 LRi_binomial_PDF(LR_obj *o, int k) - Binomial probablity (or mass) distribution function. More...
 
float LRi_binomial_CDF (LR_obj *o, int k)
 LRi_binomial_CDF(LR_obj *o, int k) - Binomial distribution cumulative distribution function. More...
 

Detailed Description

The Binomial distribution with probability of success p > 0 and n independent tests.

The pseudo-random numbers are distributed from the Binomial distribution, which is a discrete distribution describing the number of successful Bernoulli trails in n events. A Bernoulli trial is one characterized by either "success" or "failure." For example, n coin flips where the number of heads is shown is described by the Bimomial distribution. If n is large and p not "extreme" then the distribution will approach the Normal distribution, and these routines may not be as effective. This approach to a Normal distribution is established by the "central limit theorem."

The attribute p is greater than zero and less than one and represents the probability of a successful trial. Therefore, np is the mean number of successful trials in n events and also may not be an integer value.

\begin{eqnarray*} \mbox{PDF}(k) &= \left. \begin{array}{ll} \left(\begin{array}{c} {n} \\ {k} \end{array}\right) p^k (1-p)^{n-k}, & 0 \le k \le n \end{array} \right. \\ \\ \mbox{CDF}(k) &= \left. \begin{array}{ll} \sum_{i=0}^{k} \left(\begin{array}{c} {n} \\ {i} \end{array}\right) p^i (1-p)^{n-i}, & 0 \le k \le n \end{array} \right. \end{eqnarray*}

The default is $ p = \frac{1}{2} $ and q will be set to $ \frac{1}{\log(1-p)} $ for calculation efficiency. Do not set q when declaring this distribution.

BinomialDistribution.png
The plots show the distribution functions as continuous only to visually connect adjacent values but are actually discrete.

See also
LRgaus.c LRgsn.c LRgeom.c

Definition in file LRbinom.c.

Function Documentation

◆ LRi_binomial_CDF()

float LRi_binomial_CDF ( LR_obj o,
int  k 
)

LRi_binomial_CDF(LR_obj *o, int k) - Binomial distribution cumulative distribution function.

Parameters
oLR_obj object
xvalue
Returns
float CDF at x

Definition at line 133 of file LRbinom.c.

◆ LRi_binomial_PDF()

float LRi_binomial_PDF ( LR_obj o,
int  k 
)

LRi_binomial_PDF(LR_obj *o, int k) - Binomial probablity (or mass) distribution function.

Parameters
oLR_obj object
xvalue
Returns
float PDF at x

Definition at line 108 of file LRbinom.c.

◆ LRi_binomial_RAN()

int LRi_binomial_RAN ( LR_obj o)

LRi_binomial_RAN(LR_obj *o) - int Binomial distributed variate. Default values: probability of success p = 1/2.

The random variate is generated using the waiting time property - Generate a number of exponential variates until the waited sum exceeds some value.

Parameters
oLR_obj object
Returns
int

Definition at line 82 of file LRbinom.c.