Skip to content

Random Number Testing...

2 messages · Ko-Kang Kevin Wang, Brian Ripley

#
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?

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?

Thanks,

Kevin

-------------------------------------------------
Ko-Kang Kevin Wang
Statistical Analysis Division Leader
Software Developers' Klub
University of Auckland
New Zealand


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Sun, 8 Apr 2001 Ko-Kang at xtra.co.nz wrote:

            
?write  or see the R Data Import/Export manual.  Do do this in smaller
pieces, though, using connections to keep the file open.
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
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.)