[R] Using RNG from MS [forwarded message from Xiaoqiang Li]

Martin Maechler maechler at stat.math.ethz.ch
Tue Aug 22 18:15:34 CEST 2000


This had a VERY WRONG  `To:' address and went straight into my 
"spam box" into which I don't look too often ..

Martin

------- start of forwarded message -------
Message-ID: <Pine.A41.4.05.10008212237300.18590-100000 at fisher.stats.uwo.ca>
MIME-Version: 1.0
From: Xiaoqiang Li <lxq at stats.uwo.ca>
To: Majordomo-Owner at stat.math.ethz.ch
Subject: r-help
Date: Mon, 21 Aug 2000 22:39:17 -0400 (EDT)


Hi,

I am looking for help from those who know R.

I am calling R's random number generator in Microsoft Visual C/C++. The
file "R\rw1010\src\include" is included. It can be compiled, and .obj can
be generated. However, there is some trouble in linking and I don't know
how to fix it. The error message and the C codes are shown below.

Could you give me some suggestions? Thanks a lot for your help.

*************************************************************************
***************    error message       **********************************

Linking...
   Creating library Release/stochastic.lib and object
Release/stochastic.exp
stochastic.obj : error LNK2001: unresolved external symbol _PutRNGstate
stochastic.obj : error LNK2001: unresolved external symbol _unif_rand
stochastic.obj : error LNK2001: unresolved external symbol _Rf_rnorm
stochastic.obj : error LNK2001: unresolved external symbol _GetRNGstate
Release/stochastic.dll : fatal error LNK1120: 4 unresolved externals
Error executing link.exe.
*************************************************************************
************************** stochastic.c  ********************************

#include <R.h>
#include <Rinternals.h>
#include <R_ext/Mathlib.h>
#include <R_ext/Random.h>
#include <math.h>

double MS(double z, double y, double mu ){
        double d_y;
        int k;
        d_y=sqrt(-8*log(y));
        k=(int)floor( (mu+d_y/2-z)/d_y );
        return z+k*d_y;
}

double norm(double mu,double sigma,double x){
        double pi=3.141592679565;
        return 1/sqrt(2*pi*sigma)*exp(-(x-mu)*(x-mu)/sigma/sigma/2);
}

void stepzero(double *X0, double *mu0, long *length, double *X1){
        long i;
        double Z1, Y1;
        GetRNGstate();

        Z1=rnorm(0,1);
        Y1=norm(0,1,Z1)*unif_rand();
        for (i=0;i<*length;i++)
                X1[i]=MS(Z1,Y1,*X0+mu0[i]);

        PutRNGstate();
}

***************************************************************************
************************** stochastic.def ********************************
LIBRARY stochastic

EXPORTS
                            stepzero
**************************************************************************

Xiaoqiang Li

---
Dept. of Stats. & Act. Sciences
The University of Western Ontario
London, ON, Canada, N6A 5B7
Tel: (519)661-2111 ext 88212
http://www.stats.uwo.ca/phd/lxq/  

------- end of forwarded message -------
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list