title: Vectorised Rcpp random binomial draws
body: <p>This is a follow-on question from this one: <a href="https://stackoverflow.com/questions/20646666/generating-same-random-variable-in-rcpp-and-r">Generating same random variable in Rcpp and R</a></p>
  
  <p>I'm trying to speed up a vectorised call to rbinom of this form:</p>
  
  <pre><code>    x &lt;- c(0.1,0.4,0.6,0.7,0.8)
      rbinom(length(x),1 ,x)
  </code></pre>
  
  <p>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 :</p>
  
  <pre><code>    cppFunction("NumericVector cpprbinom(int n, double size, double prob) { \
           return(rbinom(n, size, prob)); }")
      set.seed(42); cpprbinom(10, 1, 0.5)
  </code></pre>
  
  <p>....and is about twice as fast as the non Rcpp option, but can't handle my vectorised version</p>
  
  <pre><code>    cpprbinom(length(x), 1, x)
  </code></pre>
  
  <p>How can the Rcpp code be modified to implement this?</p>
  
  <p>Thanks</p>