[R] using "rbinom" in C code gives me erroneous results... random variable is not random (always zero)...

From: Vumani Dlamini <dvumani_at_hotmail.com>
Date: Thu 29 Jun 2006 - 20:18:18 EST


Dear Listers,
I am trying to use "rbinom" in my C code, but i always get zeros as output no matter the probability. Am not sure what I am doing wrong because the function has worked before. Attached in an example. Noticed that "rbinom" expects 'n' to be REAL. Regards, Vumani  

R 2.3.1 (2006-06-01)
Windows XP
Gcc
/* Called this file binom.c and then ran rcmd shlib on it */#include <R.h>#include <Rmath.h>#include <math.h>#include <Rdefines.h>SEXP binomial(SEXP r, SEXP n, SEXP p){ int i; SEXP out; PROTECT(out = allocVector(REALSXP,INTEGER(r)[0])); for(i = 0; i < INTEGER(r)[0]; ++i){ REAL(out)[i] = rbinom(REAL(n)[0],REAL(p)[0]); } Rprintf("%d %f %f\n",INTEGER(r)[0],REAL(n)[0],REAL(p)[0]); UNPROTECT(1); return(out);}  

### used theses line in R
dyn.load("binom.dll").Call("binomial",as.integer(10),as.double(1),as.double(0.4))dyn.unload("binom.dll")



Try Live.com - your fast, personalized homepage with all the things you care about in one place.
http://www.live.com/getstarted

        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Jun 29 21:38:18 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 30 Jun 2006 - 00:12:32 EST.

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