register_methods | R Documentation |
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.
register_methods(kind = c("both", "rng"))
restore_methods()
kind |
Which methods should be registered? Either |
Caveats:
While runif
and dqrunif
as well as rnorm
and
dqrnorm
will produce the same results, this is not the case for
rexp
and dqrexp
.
The dqr<dist>
functions are still faster than r<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 with register_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 case set.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 after register_methods()
.
When called with a single integer as argument, both set.seed()
and dqset.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.
Invisibly returns a three-element character vector of the RNG, normal and sample kinds before the call.
RNGkind
and Random.user
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()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.