New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide access to the global RNG #41
Comments
This comment has been minimized.
This comment has been minimized.
I revisited the issue and noticed that my previous suggestion was not helpful. I came up with an alternative, simple approach (see https://github.com/hsloot/dqrng) using an If you like the approach, I could provide a PR. Notes on the implementationThe following method can be used to expose the raw pointer to the global RNG in an // src/dqrng.cpp
...
// after rng is initialized
// [[Rcpp::export(rng = false)]]
SEXP get_sxprng() {
return Rcpp::XPtr<dqrng::rng64_t::element_type>(rng.get(), false);
} This creates bindings via the Rcpp interface in // inst/include/dqrng_get_rng.h
#ifndef DQRNG_GET_RNG_H
#define DQRNG_GET_RNG_H 1
#include <Rcpp.h>
#include "dqrng.h"
#include "dqrng_generator.h"
namespace dqrng {
dqrng::rng64_t::element_type* get_rng() {
return Rcpp::XPtr<dqrng::rng64_t::element_type>(dqrng::get_sxprng()).get();
}
}
#endif // DQRNG_GET_RNG_H AlternativesI am not sure if it is also possible to directly expose the shared_ptr or the raw pointer without going through the |
Hi @hsloot. |
I tried merging both approaches and cleaning it up a bit; see #58. |
For some applications it makes sense to use a RNG directly. It is of course always possible to generate a new RNG, but that has its own independent state. It would be more convenient, if one could get access to (a shared pointer holding) the global RNG.
The text was updated successfully, but these errors were encountered: