nag_random_discrete_uniform (g05dyc) (PDF version)
g05 Chapter Contents
g05 Chapter Introduction
NAG C Library Manual

NAG Library Function Document

nag_random_discrete_uniform (g05dyc)

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

nag_random_discrete_uniform (g05dyc) returns a pseudorandom integer taken from a uniform distribution over the interval m,n .

2  Specification

#include <nag.h>
#include <nagg05.h>
Integer  nag_random_discrete_uniform (Integer m, Integer n)

3  Description

The distribution of a uniform random variable, I , is given by
P I=i = 1 n - m + 1 if   m i n P I=i = 0 otherwise ​
assuming mn . The function returns the value m + n-m + 1 y  where [ ] denotes the integer part, and y  is a pseudorandom number from a uniform distribution over (0,1), generated by nag_random_continuous_uniform (g05cac). If m>n , the roles of m  and n  are reversed.

4  References

Knuth D E (1981) The Art of Computer Programming (Volume 2) (2nd Edition) Addison–Wesley

5  Arguments

1:     mIntegerInput
2:     nIntegerInput
On entry: the end-points m  and n  of the distribution. It is not necessary that m<n .

6  Error Indicators and Warnings

None.

7  Accuracy

Not applicable.

8  Further Comments

None.

9  Example

The example program prints the first five pseudorandom integers from a uniform distribution between -5 and 5, generated by nag_random_discrete_uniform (g05dyc) after initialization by nag_random_init_repeatable (g05cbc).

9.1  Program Text

Program Text (g05dyce.c)

9.2  Program Data

None.

9.3  Program Results

Program Results (g05dyce.r)


nag_random_discrete_uniform (g05dyc) (PDF version)
g05 Chapter Contents
g05 Chapter Introduction
NAG C Library Manual

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