g05 Chapter Contents
g05 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_random_discrete_uniform (g05dyc)

## 1  Purpose

nag_random_discrete_uniform (g05dyc) returns a pseudorandom integer taken from a uniform distribution over the interval $\left[m,n\right]$.

## 2  Specification

 #include #include
 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 $m\le n$. The function returns the value $m+\left[\left(n-m+1\right)y\right]$ 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.

None.

Not applicable.

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)

None.

### 9.3  Program Results

Program Results (g05dyce.r)