nag_rand_int_geom (g05tc) generates
integers
from a discrete geometric distribution, where the probability of
(a first success after
trials) 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 nag_rand_int_geom (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 ) then a direct transformation of uniform variates is used.
One of the initialization functions
nag_rand_init_repeat (g05kf) (for a repeatable sequence if computed sequentially) or
nag_rand_init_nonrepeat (g05kg) (for a non-repeatable sequence) must be called prior to the first call to
nag_rand_int_geom (g05tc).
None.
Not applicable.
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
.
This example prints
pseudorandom integers from a geometric distribution with parameter
, generated by a single call to
nag_rand_int_geom (g05tc), after initialization by
nag_rand_init_repeat (g05kf).
function g05tc_example
fprintf('g05tc example results\n\n');
seed = [int64(1762543)];
genid = int64(1);
subid = int64(1);
[state, ifail] = g05kf( ...
genid, subid, seed);
n = int64(10);
p = 0.001;
mode = int64(3);
r = [0];
[r, state, x, ifail] = g05tc( ...
mode, n, p, r, state);
disp('Variates');
disp(double(x));