g05nd selects a pseudorandom sample without replacement from an integer vector.

Syntax

C#
```public static void g05nd(
int[] ipop,
int n,
int[] isampl,
int m,
G05..::..G05State g05state,
out int ifail
)```
Visual Basic
```Public Shared Sub g05nd ( _
ipop As Integer(), _
n As Integer, _
isampl As Integer(), _
m As Integer, _
g05state As G05..::..G05State, _
<OutAttribute> ByRef ifail As Integer _
)```
Visual C++
```public:
static void g05nd(
array<int>^ ipop,
int n,
array<int>^ isampl,
int m,
G05..::..G05State^ g05state,
[OutAttribute] int% ifail
)```
F#
```static member g05nd :
ipop : int[] *
n : int *
isampl : int[] *
m : int *
g05state : G05..::..G05State *
ifail : int byref -> unit
```

Parameters

ipop
Type: array<System..::..Int32>[]()[][]
An array of size [n]
On entry: the population to be sampled.
n
Type: System..::..Int32
On entry: the number of elements in the population vector to be sampled.
Constraint: ${\mathbf{n}}\ge 1$.
isampl
Type: array<System..::..Int32>[]()[][]
An array of size [m]
On exit: the selected sample.
m
Type: System..::..Int32
On entry: the sample size.
Constraint: $1\le {\mathbf{m}}\le {\mathbf{n}}$.
g05state
Type: NagLibrary..::..G05..::..G05State
An Object of type G05.G05State.
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

g05nd selects $m$ elements from a population vector ipop of length $n$ and places them in a sample vector isampl. Their order in ipop will be preserved in isampl. Each of the $\left(\begin{array}{c}n\\ m\end{array}\right)$ possible combinations of elements of isampl may be regarded as being equally probable.
For moderate or large values of $n$ it is theoretically impossible that all combinations of size $m$ may occur, unless $m$ is near 1 or near $n$. This is because $\left(\begin{array}{c}n\\ m\end{array}\right)$ exceeds the cycle length of any of the base generators. For practical purposes this is irrelevant, as the time taken to generate all possible combinations is many millenia.
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 g05nd.

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

Error Indicators and Warnings

Errors or warnings detected by the method:
${\mathbf{ifail}}=2$
On entry, ${\mathbf{n}}<1$.
${\mathbf{ifail}}=4$
 On entry, ${\mathbf{m}}<1$, or ${\mathbf{m}}>{\mathbf{n}}$.
${\mathbf{ifail}}=5$
 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.

Parallelism and Performance

None.

The time taken by g05nd is of order $n$.
 (a) set ${\mathbf{ipop}}\left[\mathit{i}-1\right]=\mathit{i}$, for $\mathit{i}=1,2,\dots ,n$; (b) use g05nd to take a sample from ipop and put it into isampl; (c) use the contents of isampl as a set of indices to access the relevant vector or matrix.