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

The Geometric distribution with a probability of success 0 < p < 1. More...

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

Go to the source code of this file.

Functions

int LRi_geometric_RAN (LR_obj *o)
 LRi_geometric_RAN(LR_obj *o) - int Geometric distributed variate. Default values: probability of success p = 1/2. More...
 
float LRi_geometric_PDF (LR_obj *o, int x)
 LRi_geometric_PDF(LR_obj *o, int x) - Geometric probablity (or mass) distribution function. More...
 
float LRi_geometric_CDF (LR_obj *o, int x)
 LRi_geometric_CDF(LR_obj *o, int x) - Geometric distribution cumulative distribution function. More...
 

Detailed Description

The Geometric distribution with a probability of success 0 < p < 1.

The pseudo-random numbers are distributed from the Geometric distribution, which is a discrete distribution describing the number of Bernoulli trails until a successful event. A Bernoulli trial is one characterized by either "success" or "failure." For example, the number of coin flips until a heads is shown is described by the Geometric distribution.

The attribute p is greater than zero and less than one and represents the probability of a successful trial. Therefore, 1/p is the mean number of trials until success.

\begin{eqnarray*} \mbox{PDF}(k) &= \left\{ \begin{array}{ll} 0, & k \le 0 \\ p(1-p)^{k-1}, & 0 < k . \end{array} \right. \\ \\ \mbox{CDF}(k) &= \left\{ \begin{array}{ll} 0, & k \le 0 \\ 1 - (1-p)^k, & 0 < k . \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.

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

Definition in file LRgeom.c.

Function Documentation

◆ LRi_geometric_CDF()

float LRi_geometric_CDF ( LR_obj o,
int  x 
)

LRi_geometric_CDF(LR_obj *o, int x) - Geometric distribution cumulative distribution function.

Parameters
oLR_obj object
xvalue
Returns
float CDF at x

Definition at line 112 of file LRgeom.c.

◆ LRi_geometric_PDF()

float LRi_geometric_PDF ( LR_obj o,
int  x 
)

LRi_geometric_PDF(LR_obj *o, int x) - Geometric probablity (or mass) distribution function.

Parameters
oLR_obj object
xvalue
Returns
float PDF at x

Definition at line 88 of file LRgeom.c.

◆ LRi_geometric_RAN()

int LRi_geometric_RAN ( LR_obj o)

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

The random variate is generated using inversion and truncation.

Parameters
oLR_obj object
Returns
int

Definition at line 68 of file LRgeom.c.