﻿ g05tk Method
g05tk generates a vector of pseudorandom integers, each from a discrete Poisson distribution with differing parameter.

# Syntax

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

#### Parameters

m
Type: System..::..Int32
On entry: $m$, the number of Poisson distributions for which pseudorandom variates are required.
Constraint: ${\mathbf{m}}\ge 1$.
vlamda
Type: array<System..::..Double>[]()[][]
An array of size [m]
On entry: the means, ${\lambda }_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,{\mathbf{m}}$, of the Poisson distributions.
Constraint: $0.0\le {\mathbf{vlamda}}\left[\mathit{j}-1\right]\le {\mathbf{x02bb}}/2.0$, for $\mathit{j}=1,2,\dots ,{\mathbf{m}}$.
g05state
Type: NagLibrary..::..G05..::..G05State
An Object of type G05.G05State.
x
Type: array<System..::..Int32>[]()[][]
An array of size [m]
On exit: the $m$ pseudorandom numbers from the specified Poisson distributions.
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

g05tk generates $m$ integers ${x}_{j}$, each from a discrete Poisson distribution with mean ${\lambda }_{j}$, where the probability of ${x}_{j}=I$ is
 $Pxj=I=λjI×e-λjI!, I=0,1,…,$
where
 $λj≥0, j=1,2,…,m.$
The methods used by this method have low set up times and are designed for efficient use when the value of the parameter $\lambda$ changes during the simulation. For large samples from a distribution with fixed $\lambda$ using g05tj to set up and use a reference vector may be more efficient.
When $\lambda <7.5$ the product of uniforms method is used, see for example Dagpunar (1988). For larger values of $\lambda$ an envelope rejection method is used with a target distribution:
 $fx=13if ​x≤1,fx=13x-3otherwise.$
This distribution is generated using a ratio of uniforms method. A similar approach has also been suggested by Ahrens and Dieter (1989). The basic method is combined with quick acceptance and rejection tests given by Maclaren (1990). For values of $\lambda \ge 87$ Stirling's approximation is used in the computation of the Poisson distribution function, otherwise tables of factorials are used as suggested by Maclaren (1990).
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 g05tk.

# References

Ahrens J H and Dieter U (1989) A convenient sampling method with bounded computation times for Poisson distributions Amer. J. Math. Management Sci. 1–13
Dagpunar J (1988) Principles of Random Variate Generation Oxford University Press
Maclaren N M (1990) A Poisson random number generator Personal Communication

# Error Indicators and Warnings

Errors or warnings detected by the method:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{m}}<1$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{vlamda}}\left[j-1\right]<0.0$ for at least one value of $j$.
On entry, $2×{\mathbf{vlamda}}\left[j-1\right]>{\mathbf{x02bb}}\left(\right)$ for at least one value of $j$.
${\mathbf{ifail}}=3$
 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.