register_methods {dqrng} | R Documentation |
Registering as user-supplied RNG
Description
The random-number generators (RNG) from this package can be
registered as user-supplied RNG. This way all r<dist>
functions make
use of the provided fast RNGs.
Usage
register_methods(kind = c("both", "rng"))
restore_methods()
Arguments
kind |
Which methods should be registered? Either |
Details
Caveats:
While
runif
anddqrunif
as well asrnorm
anddqrnorm
will produce the same results, this is not the case forrexp
anddqrexp
.The
dqr<dist>
functions are still faster thanr<dist>
when many random numbers are generated.You can use only the RNG from this package using
register_method("rng")
or both the RNG and the Ziggurat method for normal draws withregister_method("both")
. The latter approach is used by default. Using only the Ziggurat method will give undefined behavior and is not supported!Calling
dqset.seed(NULL)
re-initializes the RNG from R's RNG. This no longer makes sense when the RNG has been registered as user-supplied RNG. In that caseset.seed{NULL}
needs to be used.With R's in-build RNGs one can get access to the internal state using
.Random.seed
. This is not possible here, since the internal state is a private member of the used C++ classes.
You can automatically register these methods when loading this package by
setting the option dqrng.register_methods
to TRUE
, e.g.
with options(dqrng.register_methods=TRUE)
.
Notes on seeding:
When a user-supplied RNG is registered, it is also seeded from the previously used RNG. You will therefore get reproducible (but different) whether you call
set.seed()
before or afterregister_methods()
.When called with a single integer as argument, both
set.seed()
anddqset.seed()
have the same effect. However,dqset.seed()
allows you to call it with two integers thereby supplying 64 bits of initial state instead of just 32 bits.
Value
Invisibly returns a three-element character vector of the RNG, normal and sample kinds before the call.
See Also
RNGkind
and Random.user
Examples
register_methods()
# set.seed and dqset.seed influence both (dq)runif and (dq)rnorm
set.seed(4711); runif(5)
set.seed(4711); dqrunif(5)
dqset.seed(4711); rnorm(5)
dqset.seed(4711); dqrnorm(5)
# similarly for other r<dist> functions
set.seed(4711); rt(5, 10)
dqset.seed(4711); rt(5, 10)
# but (dq)rexp give different results
set.seed(4711); rexp(5, 10)
set.seed(4711); dqrexp(5, 10)
restore_methods()