From r@dford @ending from c@@toronto@edu  Thu Sep 20 17:01:33 2018
From: r@dford @ending from c@@toronto@edu (Radford Neal)
Date: Thu, 20 Sep 2018 11:01:33 -0400
Subject: [Rd] Bias in R's random integers?
In-Reply-To: <mailman.47730.5.1537438086.4546.r-devel@r-project.org>
References: <mailman.47730.5.1537438086.4546.r-devel@r-project.org>
Message-ID: <20180920150133.GA29697@mail.cs.toronto.edu>

> From: Duncan Murdoch <murdoch.duncan at 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



[Rd] Bias in R's random integers?
Radford Neal