[Rd] Bias in R's random integers?
@grubb @ending from redh@t@com
Fri Sep 21 23:33:52 CEST 2018
On Friday, September 21, 2018 12:38:15 PM EDT Tierney, Luke wrote:
> Not sure what should happen theoretically for the code in vseq.c, but
> I see the same pattern with the R generators I tried (default,
> Super-Duper, and L'Ecuyer) and with with bash $RANDOM using
> N <- 10000
> X1 <- replicate(N, as.integer(system("bash -c 'echo $RANDOM'", intern =
> TRUE))) X2 <- replicate(N, as.integer(system("bash -c 'echo $RANDOM'",
> intern = TRUE))) X <- X1 + 2 ^ 15 * (X2 > 2^14)
> and with numbers from random.org
> X <- randomNumbers(N, 0, 2^16-1, col = 1)
> So I'm not convinced there is an issue.
Indeed. I found the issue: Hex vs Decimal output. If the bash command was
printf "0x%08x\n" $RANDOM, then everything is fine. So, the code in vseq.c
needs to be strtoul(buf, NULL, 0); so that it handles Hex, Decimal, or
Octal. With this correction to vseq all is fine. No banding in any generated
image. Corrected program is uploaded.
So, the technique works. When the numbers had a problem, due to a conversion
error, it showed a distinct pattern. :-)
More information about the R-devel