g05tc generates a vector of pseudorandom integers from the discrete geometric distribution with probability p of success at a trial.

Syntax

C#
public static void g05tc(
	int mode,
	int n,
	double p,
	double[] r,
	G05..::..G05State g05state,
	int[] x,
	out int ifail
)
Visual Basic
Public Shared Sub g05tc ( _
	mode As Integer, _
	n As Integer, _
	p As Double, _
	r As Double(), _
	g05state As G05..::..G05State, _
	x As Integer(), _
	<OutAttribute> ByRef ifail As Integer _
)
Visual C++
public:
static void g05tc(
	int mode, 
	int n, 
	double p, 
	array<double>^ r, 
	G05..::..G05State^ g05state, 
	array<int>^ x, 
	[OutAttribute] int% ifail
)
F#
static member g05tc : 
        mode : int * 
        n : int * 
        p : float * 
        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.
mode=0
Set up reference vector only.
mode=1
Generate variates using reference vector set up in a prior call to g05tc.
mode=2
Set up reference vector and generate variates.
mode=3
Generate variates without using the reference vector.
Constraint: mode=0, 1, 2 or 3.
n
Type: System..::..Int32
On entry: n, the number of pseudorandom numbers to be generated.
Constraint: n0.
p
Type: System..::..Double
On entry: the parameter p of the geometric distribution representing the probability of success at a single trial.
Constraint: machine precisionp1.0 (see x02aj).
r
Type: array<System..::..Double>[]()[][]
An array of size [lr]
On entry: if mode=1, the reference vector from the previous call to g05tc.
If mode=3, r is not referenced.
On exit: if mode3, 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 n pseudorandom numbers from the specified geometric distribution.
ifail
Type: System..::..Int32%
On exit: ifail=0 unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

Description

g05tc generates n integers xi from a discrete geometric distribution, where the probability of xi=I (a first success after I+1 trials) is
Pxi=I=p×1-pI,  I=0,1,.
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 g05tc with the same parameter value can then use this reference vector to generate further variates. If the search table is not used (as recommended for small values of p) then a direct transformation of uniform variates 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 g05tc.

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:
ifail=1
On entry, mode0, 1, 2 or 3.
ifail=2
On entry, n<0.
ifail=3
On entry,p<0.0 or p>1.0,
ormode=0 or 2 and p is so small that lr would have to be larger than the largest representable integer. Use mode=3 in this case.
ifail=4
On entry, p is not the same as when r was set up in a previous call to g05tc with mode=0 or 2.
On entry, the r vector was not initialized correctly or has been corrupted.
ifail=5
On entry, lr is too small when mode=0 or 2.
ifail=6
On entry,state vector was not initialized or has been corrupted.
ifail=-9000
An error occured, see message report.
ifail=-8000
Negative dimension for array value
ifail=-6000
Invalid Parameters value

Accuracy

Not applicable.

Parallelism and Performance

None.

Further Comments

The time taken to set up the reference vector, if used, increases with the length of array r. However, if the reference vector is used, the time taken to generate numbers decreases as the space allotted to the index part of r increases. Nevertheless, there is a point, depending on the distribution, where this improvement becomes very small and the suggested value for the length of array r is designed to approximate this point.
If p is very small then the storage requirements for the reference vector and the time taken to set up the reference vector becomes prohibitive. In this case it is recommended that the reference vector is not used. This is achieved by selecting mode=3.

Example

See Also