Random Number Generator for R 3.6.1

As suggested by @JanvanderLaan in the comments, a possible problem might stem from an .RData file being loaded upon start up. For example if one had a previous version of R installed an every used it, the initial working directory from getwd() upon starting up a session will contain an .RData file and a .Rhistory file, if one ever saved the session. Usually this is the documents folder on windows if one uses Rstudio, which most individuals goes out of their way to clear of old or unusual files.

Following the suggestion in the comment, going to the directory output by getwd() in a fresh R session, I found an .RData file, closed the existing R sessions without saving the current session, and reopened a new R session. And it seems to have correctly fixed the problem as can be seen below. Thus it seems the method for generating random numbers is indeed saved between sessions within the .Rdata file.

RNGkind()
[1] "Mersenne-Twister" "Inversion"        "Rejection"   

Edit (illustration)

We can actually quite easily illustrate this in a fresh R session, regardless of which random number generator is set. Assuming one has ever opened and saved an R session prior to R-3.6.1, the following code illlustrates the problem

#Assuming that the R session has just opened
>RNGkind()
[1] "Mersenne-Twister" "Inversion"        "Rounding"  
>RNGversion("3.6.1") 
>RNGkind()
[1] "Mersenne-Twister" "Inversion"        "Rejection"  
>load(".RData", verbose = TRUE)
Loading objects:
  .Random.seed
>RNGkind()
[1] "Mersenne-Twister" "Inversion"        "Rounding"  

As can be seen, it stores the .Random.seed, however what is not shown is that the type of random number generator is also imported, upon loading the previous environment. Executing

file.remove(".RData")
q("no")

should thus fix the issue for future sessions, assuming working directory has not been changed in the current session.


I had hoped that setting a bounty would extract a definite answer to what caused OP's problem. While that didn't happen, some comments and answers suggested a few reasons. I provide an additional answer here to put them all in one place and provide a little better illustration for how to tell when one thing is happening versus the other.

Suggested causes:

  • Seed being set by a .RData file in the initial working directory
  • RNG type being set by .Rprofile
  • Bug in a recent patch

Seed set by a .RData file

As discussed in Oliver's answer, this could be caused by a .RData file in your initial working directory. I won't go into much more detail (you can consult the linked answer for that), but I did want to show what you would see on startup if that were the case. This is what the start up message in R looks like on my machine:

R version 3.6.1 (2019-07-05) -- "Action of the Toes"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-pc-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.

  Natural language support but running in an English locale

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.

>

If you are reading in a .RData file on startup that could cause that, you'd see a notification about that right after the last paragraph of the startup message:

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.

[Workspace loaded from ~/.RData]

RNG type set by .Rprofile

.Rprofile is a script that runs on startup that you can use to set some settings at the outset of your session. (You can read a little more about it here or here, or in the R documentation). Though I doubt this is the case for you, it is at least possible the problem was caused by a .Rprofile file being run with a line something like the following

RNGkind(sample.kind = "Rounding")

If you had such a setting in a .Rprofile file that was causing your problem, you'd see a warning at the end of your startup message:

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.

Warning message:
In RNGkind(sample.kind = "Rounding") : non-uniform 'Rounding' sampler used

Bug

If you see neither of those messages at startup, my best guess is that this is caused by some kind of bug introduced in a recent patch to R 3.6.1. I kind of hesitate to say that, but I can't see another option (I had kind of hoped that offering a bounty would draw an answer that provided such another option). If so, I'd report it as a bug; find out more here.

Tags:

R