Random Integer Pattern in Rcpp

This may be a very simple question, but I cannot find it. How can I select a random integer from 1 to N in Rcpp? I know that I can try a single number and round it or enable the sample function for use in C ++ code, but both of them do not seem to be correct.

+6
source share
1 answer
  • AFIACR we donโ€™t have a โ€œdecentโ€ (i.e. vector) sample() ) function in Rcpp-land, but Christian Gunning is working on one based on Armadillo through RcppArmadillo.

  • You can, of course, sample from U (0,1), scale to N and for the rest. We have R::runif() for the scalar case and runif() in the sugar, which is vectorized.

Edit: as of 2017, both RcppArmadillo and Rcpp now have a sample() function.

+6
source

All Articles