Vectorised Rcpp random binomial draws
问题 This is a follow-on question from this one: Generating same random variable in Rcpp and R I'm trying to speed up a vectorised call to rbinom of this form: x <- c(0.1,0.4,0.6,0.7,0.8) rbinom(length(x),1 ,x) In the live code of x is a vector of variable length (but typically numbering in the millions). I have no experience with Rcpp but I was wondering could I use Rcpp to speed this up. From the linked question this Rcpp code was suggested for non-vectorised rbinom calls by @Dirk Eddelbuettel :