An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20091113/02893b62/attachment-0001.pl>
random numbers in C
3 messages · Thomas Unternaehrer, Duncan Murdoch
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
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20091113/df030392/attachment-0001.pl>