[Rd] Bias in R's random integers?

Dirk Eddelbuettel edd @ending from debi@n@org
Fri Sep 21 16:25:42 CEST 2018


Slightly nicer version:

--- snip --------------------------------------------------------------------
#include <Rcpp.h>

// [[Rcpp::export]]
Rcpp::DataFrame stevePlot(Rcpp::NumericVector itable) {
  size_t cnt = itable.size(), num = 0;
  double nth, n1th = 0, n2th = 0, n3th = 0;
  double x, y, usex, usey, pha = 0;
  std::vector<double> xv, yv;
  const double scaling = 0.5;
  usex = sin(pha);
  usey = cos(pha);
  while (num < cnt) {
    double x1, y1, z1;
    nth = itable[num];
    num++;
    x1 = (nth - n1th)  * scaling;
    y1 = (n1th - n2th) * scaling;
    z1 = (n2th - n3th) * scaling;
    x = (x1*usey+z1*usex);
    y = y1 + (z1*usey-x1*usex) / 2;
    if (num > 4) {
      xv.push_back(x);
      yv.push_back(y);
    }
    n3th=n2th; n2th=n1th; n1th=nth;
  }
  return(Rcpp::DataFrame::create(Rcpp::Named("X") = xv,
                                 Rcpp::Named("Y") = yv));
}

/*** R
library(ggplot2)
Xin <- runif(10000, min = 0, max = 65535)
Xout <- stevePlot(Xin)
qplot(X, Y, data=Xout)
*/
--- snip --------------------------------------------------------------------

Still just   Rcpp::sourceCpp("filenamehere.cpp")   it.

Dirk

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | edd using debian.org



More information about the R-devel mailing list