From edd @ending from debi@n@org  Fri Sep 21 16:25:42 2018
From: edd @ending from debi@n@org (Dirk Eddelbuettel)
Date: Fri, 21 Sep 2018 09:25:42 -0500
Subject: [Rd] Bias in R's random integers?
In-Reply-To: <5268718.ryNPvsxLyr@x2>
References: <CAN_1p9wVX=AR8aYtC2LJo0bgN9cRW3XcbYJqnVHdCzA-QA1ceg@mail.gmail.com>
 <a590bfc6-f172-b227-00d9-9eacb126fd63@gmail.com>
 <2357485.GhJh1lojO1@x2> <5268718.ryNPvsxLyr@x2>
Message-ID: <23460.65382.277446.718386@rob.eddelbuettel.com>


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 at debian.org



[Rd] Bias in R's random integers?
Dirk Eddelbuettel