I am making C within R codes.
In my C code I am using rand() function to generate random number. The R-ext.pdf says that I have to set a seed using the commands;
GetRNGstate();
PutRNGstate();
Although I am using these commands above, I am still getting different values for the same seed. Could you give me any help?
The minimum example is:
In C:
# include <R.h>
# include <Rinternals.h>
# include <Rmath.h>
# include <R_ext/Linpack.h>
SEXP example(){
SEXP output;
GetRNGstate();
PROTECT(output = allocVector(INTSXP, 1));
INTEGER(output)[0] = rand() % 50;
PutRNGstate();
UNPROTECT(1);
return(output);
}
In R:
dyn.load("example.so")
## The following codes return different values at ever run
set.seed(1)
.Call("example")
Thanks in advance.