nag_return_discrete (g05eyc) (PDF version)
g05 Chapter Contents
g05 Chapter Introduction
NAG C Library Manual

NAG Library Function Document

nag_return_discrete (g05eyc)

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

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

2  Specification

#include <nag.h>
#include <nagg05.h>
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 y x  and CDF y-1 < x .

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).

6  Error Indicators and Warnings

None.

7  Accuracy

Not applicable.

8  Further Comments

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)

9.2  Program Data

None.

9.3  Program Results

Program Results (g05eyce.r)


nag_return_discrete (g05eyc) (PDF version)
g05 Chapter Contents
g05 Chapter Introduction
NAG C Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2012