[Rd] Bias in R's random integers?
Radford Neal
r@dford @ending from c@@toronto@edu
Thu Sep 20 17:01:33 CEST 2018
> From: Duncan Murdoch <murdoch.duncan using gmail.com>
> Let's try it:
>
> > m <- (2/5)*2^32
> > m > 2^31
> [1] FALSE
> > x <- sample(m, 1000000, replace = TRUE)
> > table(x %% 2)
>
> 0 1
> 399850 600150
>
> Since m is an even number, the true proportions of evens and odds should
> be exactly 0.5. That's some pretty strong evidence of the bug in the
> generator.
It seems to be a recently-introduced bug. Here's output with R-2.15.1:
R version 2.15.1 (2012-06-22) -- "Roasted Marshmallows"
Copyright (C) 2012 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-unknown-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> set.seed(123)
> m <- (2/5)*2^32
> m > 2^31
[1] FALSE
> x <- sample(m, 1000000, replace = TRUE)
> table(x %% 2)
0 1
499412 500588
So I doubt that this has anything to do with bias from using 32-bit
random values.
Radford Neal
More information about the R-devel
mailing list