﻿ g05te Method
g05te generates a vector of pseudorandom integers from the discrete hypergeometric distribution of the number of specified items in a sample of size $l$, taken from a population of size $k$ with $m$ specified items in it.

# Syntax

C#
```public static void g05te(
int mode,
int n,
int ns,
int np,
int m,
double[] r,
G05..::..G05State g05state,
int[] x,
out int ifail
)```
Visual Basic
```Public Shared Sub g05te ( _
mode As Integer, _
n As Integer, _
ns As Integer, _
np As Integer, _
m As Integer, _
r As Double(), _
g05state As G05..::..G05State, _
x As Integer(), _
<OutAttribute> ByRef ifail As Integer _
)```
Visual C++
```public:
static void g05te(
int mode,
int n,
int ns,
int np,
int m,
array<double>^ r,
G05..::..G05State^ g05state,
array<int>^ x,
[OutAttribute] int% ifail
)```
F#
```static member g05te :
mode : int *
n : int *
ns : int *
np : int *
m : int *
r : float[] *
g05state : G05..::..G05State *
x : int[] *
ifail : int byref -> unit
```

#### Parameters

mode
Type: System..::..Int32
On entry: a code for selecting the operation to be performed by the method.
${\mathbf{mode}}=0$
Set up reference vector only.
${\mathbf{mode}}=1$
Generate variates using reference vector set up in a prior call to g05te.
${\mathbf{mode}}=2$
Set up reference vector and generate variates.
${\mathbf{mode}}=3$
Generate variates without using the reference vector.
Constraint: ${\mathbf{mode}}=0$, $1$, $2$ or $3$.
n
Type: System..::..Int32
On entry: $n$, the number of pseudorandom numbers to be generated.
Constraint: ${\mathbf{n}}\ge 0$.
ns
Type: System..::..Int32
On entry: $l$, the sample size of the hypergeometric distribution.
Constraint: $0\le {\mathbf{ns}}\le {\mathbf{np}}$.
np
Type: System..::..Int32
On entry: $k$, the population size of the hypergeometric distribution.
Constraint: ${\mathbf{np}}\ge 0$.
m
Type: System..::..Int32
On entry: $m$, the number of specified items of the hypergeometric distribution.
Constraint: $0\le {\mathbf{m}}\le {\mathbf{np}}$.
r
Type: array<System..::..Double>[]()[][]
An array of size [lr]
On entry: if ${\mathbf{mode}}=1$, the reference vector from the previous call to g05te.
If ${\mathbf{mode}}=3$, r is not referenced.
On exit: if ${\mathbf{mode}}\ne 3$, the reference vector.
g05state
Type: NagLibrary..::..G05..::..G05State
An Object of type G05.G05State.
x
Type: array<System..::..Int32>[]()[][]
An array of size [n]
On exit: the pseudorandom numbers from the specified hypergeometric distribution.
ifail
Type: System..::..Int32%
On exit: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# Description

g05te generates $n$ integers ${x}_{i}$ from a discrete hypergeometric distribution, where the probability of ${x}_{i}=I$ is
The variates can be generated with or without using a search table and index. If a search table is used then it is stored with the index in a reference vector and subsequent calls to g05te with the same parameter values can then use this reference vector to generate further variates. The reference array is generated by a recurrence relation if $lm\left(k-l\right)\left(k-m\right)<50{k}^{3}$, otherwise Stirling's approximation is used.
One of the initialization methods (G05KFF not in this release) (for a repeatable sequence if computed sequentially) or (G05KGF not in this release) (for a non-repeatable sequence) must be called prior to the first call to g05te.

# References

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

# Error Indicators and Warnings

Errors or warnings detected by the method:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{mode}}\ne 0$, $1$, $2$ or $3$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{n}}<0$.
${\mathbf{ifail}}=3$
 On entry, ${\mathbf{ns}}>{\mathbf{np}}$, or ${\mathbf{ns}}<0$.
${\mathbf{ifail}}=4$
On entry, ${\mathbf{np}}<0$.
${\mathbf{ifail}}=5$
 On entry, ${\mathbf{m}}>{\mathbf{np}}$, or ${\mathbf{m}}<0$.
${\mathbf{ifail}}=6$
On entry, at least one of ns, np or m is not the same as when r was set up in a previous call to g05te with ${\mathbf{mode}}=0$ or $2$.
On entry, the r vector was not initialized correctly or has been corrupted.
${\mathbf{ifail}}=7$
On entry, lr is too small when ${\mathbf{mode}}=0$ or $2$.
${\mathbf{ifail}}=8$
 On entry, state vector was not initialized or has been corrupted.
${\mathbf{ifail}}=-9000$
An error occured, see message report.
${\mathbf{ifail}}=-8000$
Negative dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$

Not applicable.

None.

None.