[R] R equivilant to RAND_MAX in C

Rajarshi Guha rxg218 at psu.edu
Tue Mar 23 19:02:13 CET 2004


On Tue, 2004-03-23 at 02:40, Prof Brian Ripley wrote:
> On Mon, 22 Mar 2004, Rajarshi Guha wrote:
> 
> > Hello,
> >   I have some C code that I'm interfacing to R using the .C calling
> > interface. Currently the C code uses the rand() function from the GNU C
> > library to generate random numbers. Since I need the random numbers in a
> > range from 0 to a (where a is an integer) I use the RAND_MAX macro as
> > 
> > (int)(rand() * (float)(*nobs-1) / (RAND_MAX+1.0))
> > 
> > (taken from the rand() manpage)
> 
> That isn't a random *number*: it is a random *integer*.  It is a random 
> integer on 0, ..., a=*nobs-2: is that what you wanted?

Yes. Thank you for the pointers

-------------------------------------------------------------------
Rajarshi Guha <rxg218 at psu.edu> <http://jijo.cjb.net>
GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE
-------------------------------------------------------------------
Does Ramanujan know Polish?
-- E.B. Ross




More information about the R-help mailing list