[R] Random Number Testing...

Prof Brian D Ripley ripley at stats.ox.ac.uk
Sun Apr 8 10:33:18 CEST 2001


On Sun, 8 Apr 2001 Ko-Kang at xtra.co.nz wrote:

> Hi,
>
> Suppose I want to test a set of random numbers (using the Binormal random
> number generator), input the following command to generate a set of random
> numbers:
>      test <- rbinom( 10000000, 1, 0.5 )
>
> How can I, after obtaining the result, export the vector "test" into an text
> file?

?write  or see the R Data Import/Export manual.  Do do this in smaller
pieces, though, using connections to keep the file open.


> Then, suppose I want to do something like:
>      > x <- 1e10
>      > x
>      [1] 1e+10
>      > test <- rbinom( x, 1, 0.5 )
>      Error in rbinom(n, size, prob) : invalid arguments
>
> Why would I get the error message given that x is a number?

Assuming you have a 32-bit machine, you can't allocate storage for 10
billion random numbers, and I think you also have an integer overflow
problem (10 billion is bigger than 2^32).  In either case, n is invalid.

I don't get that error message but

> test <- rbinom( x, 1, 0.5 )
Error: cannot allocate vector of size 4194303 Kb

on Solaris.  On i686 Linux I get what you reported.  Probably asInteger
behaves differently, as it just takes (int) on a double, and I don't
think the behaviour of that when the double is out of range is prescribed
in the C standard.

Finally, if you could get 10billion numbers out, testing them is not really
fair as that's far more than one could reasonably use in an R simulation.
(Quick sanity check: they would take a week or so just to generate on a
1GHz machine.)


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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