PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_rand_init_leapfrog (g05kh)
Purpose
nag_rand_init_leapfrog (g05kh) allows for the generation of multiple, independent, sequences of pseudorandom numbers using the leap-frog method.
Syntax
Description
nag_rand_init_leapfrog (g05kh) adjusts a base generator to allow multiple, independent, sequences of pseudorandom numbers to be generated via the leap-frog method (see the
G05 Chapter Introduction for details).
If, prior to calling
nag_rand_init_leapfrog (g05kh) the base generator defined by
state would produce random numbers
, then after calling
nag_rand_init_leapfrog (g05kh) the generator will produce random numbers
.
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_init_leapfrog (g05kh).
The leap-frog algorithm can be used in conjunction with the NAG basic generator, both the Wichmann–Hill I and Wichmann–Hill II generators, the Mersenne Twister and L'Ecuyer.
References
Knuth D E (1981) The Art of Computer Programming (Volume 2) (2nd Edition) Addison–Wesley
Parameters
Compulsory Input Parameters
- 1:
– int64int32nag_int scalar
-
, the total number of sequences required.
Constraint:
.
- 2:
– int64int32nag_int scalar
-
, the number of the current sequence.
Constraint:
.
- 3:
– int64int32nag_int array
-
Note: the actual argument supplied
must be the array
state supplied to the initialization routines
nag_rand_init_repeat (g05kf) or
nag_rand_init_nonrepeat (g05kg).
Contains information on the selected base generator and its current state.
Optional Input Parameters
None.
Output Parameters
- 1:
– int64int32nag_int array
-
Contains updated information on the state of the generator.
- 2:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
-
-
Constraint: .
-
-
Constraint: .
-
-
On entry,
state vector has been corrupted or not initialized.
-
-
On entry, cannot use leap-frog with the base generator defined by
state.
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
Not applicable.
Further Comments
The leap-frog method tends to be less efficient than other methods of producing multiple, independent sequences. See the
G05 Chapter Introduction for alternative choices.
Example
This example creates three independent sequences using
nag_rand_init_leapfrog (g05kh), after initialization by
nag_rand_init_repeat (g05kf). Five variates from a uniform distribution are then generated from each sequence using
nag_rand_dist_uniform01 (g05sa).
Open in the MATLAB editor:
g05kh_example
function g05kh_example
fprintf('g05kh example results\n\n');
seed = [int64(1762543)];
genid = int64(1);
subid = int64(1);
lstate = int64(17);
lseed = int64(1);
n = int64(3);
nv = int64(5);
state = zeros(lstate, n, 'int64');
x = zeros(nv, n);
[state1, ifail] = g05kf( ...
genid, subid, seed);
for i=1:n
state(:, i) = state1;
[state(:, i), ifail] = g05kh( ...
n, i, state(:,i));
end
for i=1:n
[state(:, i), x(:, i), ifail] = g05sa( ...
nv, state(:, i));
end
for i=1:n
fprintf(' Stream %d\n', i);
disp(x(:,i));
end
g05kh example results
Stream 1
0.7460
0.4925
0.4982
0.2580
0.5938
Stream 2
0.7983
0.3843
0.6717
0.6238
0.2785
Stream 3
0.1046
0.7871
0.0505
0.0535
0.2375
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015