Displaying 20 results from an estimated 7000 matches similar to: "random seed question"
2004 Mar 03
1
generating normal numbers: GetRNGstate, PutRNGstate
Hi
I'd like to generate thousands of normal numbers from my C function using
the C API functions provided R. I have two options:
1. double norm_rand(); (page 61 of R extension 1.8.1)
2. double rnorm(double mu, double sigma); (page 58 of R extension 1.8.1)
If my understanding of R-exts is correct, then I only need to call
GetRNGstate once, and then call 1000 norm_rand, and then call
2005 Jun 28
1
GetRNGstate() crashes in Windows
Hi,
Has anyone managed to successfully call GetRNGstate() / PutRNGstate()
without crashing in a Windows environment (spec. XP)? I've compiled
successfully using both the latest Cygwin, latest Mingw, and the version
of Mingw suggested in "Building R for Windows" website, but when the
executable runs, it crashes; the functions themselves can run when I omit
2008 Jul 03
1
GetRNGstate and PutRNGstate
Hi,
I've got a simulation function, written in C and called from R, that
uses the R random number functions. It's not a very complicated
simulation - 280 lines total, with the main function (the one called
with .C) repeatedly calling another function, with multiple calls to
unif_rand() in both functions. At the beginning of the main function I
call GetRNGstate(), and the last thing I do
2005 Nov 30
1
RNG stuck via Fortran call
Having not much success with my previous question I try to reformulate it:
I'm simulating a Markow chain in Fortran interfaced with R.
Each loop of my Fortran calls various functions of the R RNG through
the wrapper given below.
In a run of 100 iterations of the Markov kernel,
after 20 iterations, the RNG seems like frozen.
For example, the first call to the RNG in my loop is:
2009 Jul 30
3
user supplied random number generators
?Random.user says (in svn trunk)
Optionally,
functions \code{user_unif_nseed} and \code{user_unif_seedloc} can be
supplied which are called with no arguments and should return pointers
to the number of seeds and to an integer array of seeds. Calls to
\code{GetRNGstate} and \code{PutRNGstate} will then copy this array to
and from \code{.Random.seed}.
And it offers as an example
void
2002 Jan 24
2
random number generation issues with r and compiled C code
Dear People,
I have been writing a simulation routine that is currently entirely
written in c++. I've been using the R standalone math library to give me
random number generation for this. However, I have had to set the seed
myself, and I am using
set_seed(time(NULL), clock)
for every call to unif_rand().
However, this works really badly. The random numbers aren't uniform at
all. Does
2002 Jan 14
1
trouble using R Mathlib as standalone
Dear People,
I am trying to use R's Math library as standalone, as documented in
/src/nmath/standalone. I am using C++ in Debian testing, and the versions
are as follows:
ii g++-3.0 3.0.3-1 The GNU C++ compiler.
ii r-mathlib 1.4.0-1 `GNU S' - Standalone R math library
I have a file (rand.cc) as follows. I don't think that lattice.hh or mh.hh
are very
2005 Jun 14
1
Calling C from Fortran
I would like to call C routines from Fortran as suggested in section 5.6 of
the "Writing R extensions" documentation.
I'm familiar with Fortran but not with C.
I understand the example provided in Fortran:
subroutine testit()
double precision normrnd, x
call rndstart()
x = normrnd()
call dblepr("X was", 5, x, 1)
call rndend()
end
but I don't understand the purpose
2011 Nov 17
3
.Call in R
Hi R developers,
I am new to this forum and hope someone can help me with .Call in R.
Greatly appreciate any help!
Say, I have a vector called "vecA" of length 10000, I generate a vector
called "vecR" with elements randomly generated from Uniform[0,1]. Both vecA
and vecR are of double type. I want to replace elements vecA by elements in
vecR only if sum of elements in
2006 Feb 21
4
simple C function segfaults
Hello,
I use the simplest of examples that somebody can think
of in order to generate a matrix of random numbers
from within C, calling appropriate R functions. The
concrete example is below:
--- file pico.c
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <R.h>
#include <Rmath.h>
#define COLM( i, j, m ) ( m*j + i)
void pico ( double *y, int n,
2005 Jun 14
3
Calling C from Fortran
I would like to call C routines from Fortran under linux as suggested in
section 5.6 of
the "Writing R extensions" documentation.
I'm familiar with Fortran but not with C.
I understand the example provided in Fortran:
subroutine testit()
double precision normrnd, x
call rndstart()
x = normrnd()
call dblepr("X was", 5, x, 1)
call rndend()
end
but I don't understand
2006 Mar 07
2
double pointer matrix
Hello,
I'm having some difficulty to understand how I could
take the proper result from the following listing:
-- cut ---
#include <stdlib.h>
#include <R.h>
#include <Rmath.h>
void retMat ( double **y, int *n, int *m, double *a,
double *b) {
int i, j;
y = malloc( (*n) * sizeof( double ) );
for (i=0; i<*n; i++) {
y[i] = malloc (
2009 Nov 16
2
(Parallel) Random number seed question...
Hi All,
I have k identical parallel pieces of code running, each using n.rand
random numbers.? I would like to use the same RNG (for now), and set
the seeds so that I can guarantee that there are no overlaps in the
random numbers sampled by the k pieces of code.? Another side goal is
to have reproducibility of my results.? In?the past I have used C with
SPRNG for this task, but I'm hoping
2011 Aug 04
1
How to seed the R random number generator in C (standalone) with an instance of .Random.seed
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
2009 Jun 30
3
Matrix with random number
Hello!
I have a program in Fortran and would like to build a matrix with random numbers, I have a function in C.
However, I have problems with the use of function in R.
Code to compile: R CMD SHLIB mat.f myrbeta.c -o func.so
Code in C.
#include <R.h>
#include <Rmath.h>
void F77_SUB(fseedi)(void){
GetRNGstate();
}
void F77_SUB(fseedo)(void){
PutRNGstate();
}
void
2010 Jun 15
1
Error when callin g C-Code
Hi
when I call the function below in R, i get the error: Object 'pairlist'
can't be converted to 'double'.
#include <R.h>
#include <Rdefines.h>
#include <Rmath.h>
SEXP CSimPoisson(SEXP lambda, SEXP tgrid, SEXP T2M, SEXP Ni, SEXP NT)
{
double sign, EVar;
double *xlambda, *xtgrid, *xT2M, *xNi, *xNT, *xtau;
SEXP tau;
int ltgrid =0;
int i = 0;
int j = 0;
2006 Aug 03
1
question about dll crashing R
I have ported some R code to C to make it faster.
I can perform .Call("foobar",....) once and it
works fine. Absolutely correct answer.
If I put a loop inside foobar and run the main code
routine more than 100 times, it crashes R.
Or if I call .Call("foobar"....) seperately more than
two tims it crashes R.
For the most part I am doing matirx multiplies using
EXP
2013 Jun 07
0
[Rcpp-devel] Setting the R random seed from Rcpp
This would be easier if base::set.seed() accepted a value of .Random.seed
instead of just a scalar integer or, new to R-3.0.0, NULL. If set.seed() returned the
previous value of .Random.seed (NULL if there was no previous value) things
might be even easier. People should not have to know where .Random.seed
is stored.
S+'s set.seed() accepts a value of .Random.seed but does not return the
2009 Nov 13
2
random numbers in C
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")
2015 Apr 21
2
shlib problems with Intel compiler
Hi,
I'm encountering trouble compiling caTools_1.17.1.tar.gz and e1071_1.6-4.tar.gz on a Linux system using the Intel compiler suite. 14 other packages I generally use installed without any trouble. I notice both of these trouble packages have a C++ component, so I wonder if that might be the issue. Below, there's information on my platform, compiler, and some diagnostic output showing