Skip to content

[Rcpp-devel] Rcpp equivalent of sample()?

2 messages · Douglas Bates, Dirk Eddelbuettel

#
You can check what is done in R itself in the R sources but I imagine that
it uses a uniform random variate converted to an integer through the
cumulative probabilities. The good news is that it is easy to create the
cumulative weights with the std::accumulate function.
On May 14, 2011 4:12 PM, "Chris DuBois" <chris.dubois at gmail.com> wrote:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20110514/f41295a0/attachment-0001.htm>
#
On 14 May 2011 at 16:33, Douglas Bates wrote:
| You can check what is done in R itself in the R sources but I imagine that it
| uses a uniform random variate converted to an integer through the cumulative
| probabilities. The good news is that it is easy to create the cumulative
| weights with the std::accumulate function.

Good point. I just looked at src/main/random.c in the R sources, and the main
worker functions are once again defined as hidden.  Sigh.  May make sense to
'port' this as helper functions for Rcpp::IntegerVector.

Dirk