[Rd] user supplied random number generators

William Dunlap wdunlap at tibco.com
Thu Jul 30 20:23:41 CEST 2009


src/arithmetic.c will not compile if ints are not 32 bits and I suspect
that there is other code that will not work correctly if ints are not
32 bits
   src/arithmetic.c:
    574 #ifndef INT_32_BITS
    575 /* configure checks whether int is 32 bits.  If not this code
will
    576    need to be rewritten.  Since 32 bit ints are pretty much
universal,
    577    we can worry about writing alternate code when the need
arises.
    578    To be safe, we signal a compiler error if int is not 32 bits.
*/
    579 # error code requires that int have 32 bits
    580 #else
http://www.unix.org/version2/whatsnew/lp64_wp.html is rather old
but says that keeping int at 32 bits is the way to go for the forseeable
future.

I would recommend using Int32, as it makes the intent clearer.  The
seed does not need to be stored as nseed Sint's (the C type used to
store R/S/S+ integers: int in R, long in S and S+) but as nseed Int32's.

When I implemented this interface in S+ I used unsigned 32-bit ints
internally, so they would not suffer sign extension when naively
converted to the (signed) longs S+ uses for integer datsets like
.Random.seed.

Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com  

> -----Original Message-----
> From: r-devel-bounces at r-project.org 
> [mailto:r-devel-bounces at r-project.org] On Behalf Of Ross Boylan
> Sent: Thursday, July 30, 2009 9:52 AM
> To: Christophe Dutang
> Cc: R-devel
> Subject: Re: [Rd] user supplied random number generators
> 
> On Thu, 2009-07-30 at 12:32 +0200, Christophe Dutang wrote:
> > > This suggests that the type of user_unif_seedloc is 
> Int32*, not int
> > *.
> > > It also suggests that user_unif_nseed should return the number of
> > 32  
> > > bit
> > > integers.  The code for PutRNGstate(), for example, uses them in
> > just
> > > that way.
> > >
> > > While the dominant model, even on 64 bit hardware, is 
> probably to  
> > > leave
> > > int as 32 bit, it doesn't seem wise to assume that is always the
> > case.
> > 
> > You can test the size of an int with a configure script. see for  
> > example the package foreign, the package randtoolbox (can be found
> > in  
> > Rmetrics R forge project) I maintain with Petr Savicky.
> http://cran.r-project.org/doc/manuals/R-admin.html#Choosing-be
> tween-32_002d-and-64_002dbit-builds says "All current 
> versions of R use 32-bit integers".
> 
> Also, sizeof(int) works at runtime.  But my question was really about
> whether code for user defined RNGs should be written using 
> Int32 or int
> as the target type for the state vector.  The R core code 
> suggests to me
> one should use Int32, but the documentation says int.
> 
> Ross
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 



More information about the R-devel mailing list