The RNGs and distributions functions can also be used from C++ at various levels of abstraction. Technically there are three ways to make use of dqrng at the C++ level:
// [[Rcpp::depends(dqrng)]]
together with
Rcpp::sourceCpp()
Rcpp::cppFunction(depends = "dqrng", ...)
LinkingTo: dqrng
The following functions are also available if you include
dqrng.h
. Note that the scalar function
dqrng::runif
, dqrng::rnorm
, and
dqrng::rexp
have been deprecated and will be removed in a
future release. Please use the more flexible and faster
dqrng::random_64bit_accessor
together with
variate<Dist>()
instead.
void dqrng::dqset_seed(Rcpp::IntegerVector seed,
Rcpp::Nullable<Rcpp::IntegerVector> stream = R_NilValue)
void dqrng::dqRNGkind(std::string kind, const std::string& normal_kind = "ignored")
seed
stream
kind
normal-kind
RNGkind
Rcpp::NumericVector dqrng::dqrunif(size_t n, double min = 0.0, double max = 1.0)
DEPRECATED double dqrng::runif(double min = 0.0, double max = 1.0)
n
min
max
Rcpp::NumericVector dqrng::dqrnorm(size_t n, double mean = 0.0, double sd = 1.0)
DEPRECATED double dqrng::rnorm(double mean = 0.0, double sd = 1.0)
n
mean
sd
Rcpp::NumericVector dqrng::dqrexp(size_t n, double rate = 1.0)
DEPRECATED double dqrng::rexp(double rate = 1.0)
n
rate
n
Rcpp::IntegerVector dqrng::dqsample_int(int n, int size, bool replace = false,
Rcpp::Nullable<Rcpp::NumericVector> probs = R_NilValue,
int offset = 0)
Rcpp::NumericVector dqrng::dqsample_num(double n, double size, bool replace = false,
Rcpp::Nullable<Rcpp::NumericVector> probs = R_NilValue,
int offset = 0)
n
size
replace
prob
offset
[offset, offset + m)
The two functions are used for “normal” and “long-vector” support in R.
std::vector<std::string> dqrng::dqrng_get_state()
void dqrng::dqrng_set_state(std::vector<std::string> state)
state
std::vector<std::string>
as produced by
dqrng_get_state()
Direct usage of this method is discouraged. The
preferred way of accessing the global RNG is to instantiate
dqrng::random_64bit_accessor
within your function. Note
that you MUST NOT delete the global RNG. Using
dqrng::random_64bit_accessor
makes this impossible. In
addition, you SHOULD NOT store a reference to the RNG permanently,
because it can be invalidated by calls to dqRNGkind
.
Therefore, instances of dqrng::random_64bit_accessor
SHOULD
be stored as (non-static) variables in functions.
Note that dqrng::random_64bit_accessor
supports UniformRandomBitGenerator
and can therefore be used together with any C++11 distribution function.
In addition, the following functions are supported, since they are
inherited from the abstract parent class
random_64bit_generator
:
// clone RNG and select a different stream
std::unique_ptr<random_64bit_generator> clone(uint64_t stream)
// uniform doubles in [0,1) and double-int-pairs
double uniform01()
std::pair<double, int> generate_double_8bit_pair()
// uniform integers in a range
uint32_t operator() (uint32_t range)
uint64_t operator() (uint64_t range)
ResultType variate<ResultType, DistTmpl>(param1, ... paramN)
generate<DistTmpl>(container, param1, ... paramN)
generate<DistTmpl>(start, end, param1, ... paramN)
Dist::result_type variate<Dist>(param1, ... paramN)
generate<Dist>(container, param1, ... paramN)
generate<Dist>(start, end, param1, ... paramN)
stream
range
[0, range]
ResultType
DistTmpl
DistTmpl
std::uniform_distribution
.
DistTmpl<ResultType>
defines the full distribution.
Dist
std::uniform_distribution<double>
or
dqrng::normal_distriubtion
.
param1, ... paramN
container
std::begin
and
std::end
.
start, end