From p.dalgaard@kubism.ku.dk  Tue Jun  3 18:21:57 1997
From: p.dalgaard@kubism.ku.dk (Peter Dalgaard BSA)
Date: 03 Jun 1997 19:21:57 +0200
Subject: R-alpha: unif_rand() again
In-Reply-To: Kurt Hornik's message of Tue, 3 Jun 1997 17:17:29 +0200
References: <199706031445.QAA13652@aragorn.ci.tuwien.ac.at>
 <x2yb8r4t31.fsf@bush.kubism.ku.dk>
 <199706031517.RAA13734@aragorn.ci.tuwien.ac.at>
Message-ID: <x2pvu34n62.fsf@bush.kubism.ku.dk>

Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at> writes:

> I did.  I hoped that something like
> 
> static char *func = "runif";
> 
> double unif_rand() {
...
> 
> might work, but it does not ...

Here's a model that does (seem to) work:

> dyn.load("runif.so");.C("select_rand",runif); .C("unif_rand",3.3)
[[1]]
function (n, min = 0, max = 1) 
.Internal(runif(n, min, max))

[[1]]
[1] 0.126975

> .C("unif_rand",3.3) # the 3.3 is just an arbitrary double...
[[1]]
[1] 0.9233792

> .C("unif_rand",3.3)
[[1]]
[1] 0.03410953

> 

with

runif.c:

-------------------------

static void * func;

double select_rand(void * f)
{
        func = f;
}

static long one = 1L, zero = 0L;
unif_rand(double *x) {
  void *in[3];
  char *modes[] = { "integer", "integer", "integer" };
  long lengths[] = { 1, 1, 1 };  
  double result;
  double *values[1];

  in[0] = (void *)&one;
  in[1] = (void *)&zero;
  in[2] = (void *)&one;  
  call_S((void *)func, 3L, in, modes, lengths, 0L, 1L, values);
  x[0] = values[0][0];
}

--------------------------


-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-devel 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-devel-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


R-alpha: unif_rand() again
Peter Dalgaard BSA