On 11/13/2009 11:41 AM, Thomas Unternaehrer wrote:
I need some random numbers in my C program. Here a small example://////////////////////////////////////////////////////////////////////////////// #include <R.h> void rand (int* n) { int len = *n; for (int i = 0; i < len; i++) Rprintf("%1.5f ", unif_rand()); } dyn.load("rand.dll") .C("rand", as.integer(10)) dyn.unload("rand.dll") //////////////////////////////////////////////////////////////////////////////// But this gives me 10 times the number 0.00000 (I need 10 numbers between 0 and 1). Can somebody give me a hint what I'm doing wrong (or misunderstand).
At a minimum, you forgot to call GetRNGState and PutRNGState. See Writing R Extensions for details. But if you are running this from outside of R, you'll also need to read about building a standalone Mathlib.
Duncan Murdoch ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.

