-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeom.cpp
More file actions
39 lines (32 loc) · 900 Bytes
/
geom.cpp
File metadata and controls
39 lines (32 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <Rcpp.h>
#include <math.h>
#include <iostream>
#include <random>
using namespace Rcpp;;
// This is a simple example of exporting a C++ function to R. You can
// source this function into an R session using the Rcpp::sourceCpp
// function (or via the Source button on the editor toolbar). Learn
// more about Rcpp at:
//
// http://www.rcpp.org/
// http://adv-r.had.co.nz/Rcpp.html
// http://gallery.rcpp.org/
//
// [[Rcpp::export]]
int cpp_geom(double p) {
std::random_device rd;
std::default_random_engine generator(rd());
std::uniform_real_distribution<double> distribution(0.0,1.0);
int t = 1;
while(distribution(generator) > p) {
t++;
}
return t;
}
// You can include R code blocks in C++ files processed with sourceCpp
// (useful for testing and development). The R code will be automatically
// run after the compilation.
//
/*** R
cpp_geom(0.1)
*/