[Rd] How to seed the R random number generator in C (standalone) with an instance of .Random.seed

From: oliver ratmann <oliver.ratmann_at_duke.edu>
Date: Thu, 04 Aug 2011 14:33:23 -0400


hello all,

I use the R standalone math library in my own C program, and the default R random number generator can be seeded with

set_seed(const unsigned int, const unsigned int).

How could I seed the RNG with an instance of .Random.seed ?

I would need this or a similar workaround for debugging purposes.

More precisely, I use the default R random number generator to sample from various distributions in my own C code

SEED<- .Random.seed
save(SEED, args, file= "last.call.R")
out<- .Call("my.fun", args)

and can reproduce segmentation faults etc via

load("last.call.R")
.Random.seed<- SEED

out<- .Call("my.fun", args)

In order to use valgrind, I wrote a little C program "debug.my.fun" that reads in 'args' and 'SEED',
and then calls "my.fun" (without the SEXP overhead of course).

But the seeds are not set accordingly and segmentation faults are not reproducible.
More precisely, I need to replace the set_seed line in the following snippet with something else.

#include <Rmath.h>
int main(int argc,char* argv[])
{

    const unsigned int SEED1= 12345, SEED2= 67890;     set_seed(SEED1, SEED2);

...

}

Thanks in advance,
Oliver

        [[alternative HTML version deleted]]



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 04 Aug 2011 - 18:44:33 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 04 Aug 2011 - 21:30:14 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive