You are having a number of issues here:
rbinom(1,1,10)
is nonsense, it gets you 'Warning message: In rbinom(1, 1, 10) : NAs produced' (and I joined two lines here for display).
So let's assume you wrote rbinom(10, 1, 0.5)
which would generate 10 draws from a binomial with p=0.5
of drawing one or zero.
Rcpp documentation is very clear about using the same RNGs, with the same seeding, via RNGScope
objects which you get for free via Rcpp Attributes (see below).
So witness this (with an indentation to fit the first line here)
R> cppFunction("NumericVector cpprbinom(int n, double size, double prob) { \
return(rbinom(n, size, prob)); }")
R> set.seed(42); cpprbinom(10, 1, 0.5)
[1] 1 1 0 1 1 1 1 0 1 1
R> set.seed(42); rbinom(10,1,0.5)
[1] 1 1 0 1 1 1 1 0 1 1
R>
I define, compile, link and load a custom C++ function cpprbinom()
here. I then set the seed, and retrieve 10 values. Resetting the seed and retrieving ten values under the same parameterisation gets the same values.
This will hold for all random distributions, unless we introduced a bug which can happen.