g05 Chapter Contents
g05 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_return_discrete (g05eyc)

## 1  Purpose

nag_return_discrete (g05eyc) returns a pseudorandom integer taken from a discrete distribution defined by a reference vector r.

## 2  Specification

 #include #include
 Integer nag_return_discrete (double *r)

## 3  Description

nag_return_discrete (g05eyc) is designed for use in conjunction with other functions in this chapter, which set up the reference vector r for specific distributions or according to a distribution specified in terms of the PDF (probability density function) or CDF (cumulative distribution function). See the g05 Chapter Introduction.
The function generates a random number $x$ from nag_random_continuous_uniform (g05cac) and searches the CDF in r for the smallest value $y$ such that CDF$\left(y\right)\ge x$ and CDF$\left(y-1\right).

## 4  References

Kendall M G and Stuart A (1969) The Advanced Theory of Statistics (Volume 1) (3rd Edition) Griffin
Knuth D E (1981) The Art of Computer Programming (Volume 2) (2nd Edition) Addison–Wesley

## 5  Arguments

1:     rdouble *Input
On entry: the reference vector for which memory has been allocated by a previous call to another g05 function. To free this memory the macro NAG_FREE should be added in your program after the final call to nag_return_discrete (g05eyc).

None.

Not applicable.

None.

## 9  Example

The example program calls nag_ref_vec_poisson (g05ecc) to set up a reference vector for a Poisson distribution with mean 2.7; it then prints the first five pseudorandom numbers generated by nag_return_discrete (g05eyc) after initialization by nag_random_init_repeatable (g05cbc).

### 9.1  Program Text

Program Text (g05eyce.c)

None.

### 9.3  Program Results

Program Results (g05eyce.r)