Home > Enterprise >  different behaviors of the pseudo RNG depending on the version of R
different behaviors of the pseudo RNG depending on the version of R

Time:05-31

I observed different behaviors of the pseudo RNG depending on the version of R (see code below).

Can someone explain this difference in behavior to me?

Best Regards,

> version; set.seed(1); rnorm(3); sample(1:100, 10);
               _                           
platform       x86_64-conda_cos6-linux-gnu 
arch           x86_64                      
os             linux-gnu                   
system         x86_64, linux-gnu           
status                                     
major          3                           
minor          5.1                         
year           2018                        
month          07                          
day            02                          
svn rev        74947                       
language       R                           
version.string R version 3.5.1 (2018-07-02)
nickname       Feather Spray               
[1] -0.6264538  0.1836433 -0.8356286
 [1] 95 66 62  6 20 17 65 36 71 46
> version; set.seed(1); rnorm(3); sample(1:100, 10);
               _                           
platform       x86_64-apple-darwin13.4.0   
arch           x86_64                      
os             darwin13.4.0                
system         x86_64, darwin13.4.0        
status                                     
major          3                           
minor          6.0                         
year           2019                        
month          04                          
day            26                          
svn rev        76424                       
language       R                           
version.string R version 3.6.0 (2019-04-26)
nickname       Planting of a Tree          
[1] -0.6264538  0.1836433 -0.8356286
 [1] 87 43 14 82 59 51 85 21 54 74

CodePudding user response:

sample was changed in version 3.6.0. From https://stat.ethz.ch/pipermail/r-announce/2019/000641.html

  • The default method for generating from a discrete uniform distribution (used in sample(), for instance) has been changed. This addresses the fact, pointed out by Ottoboni and Stark, that the previous method made sample() noticeably non-uniform on large populations. See PR#17494 for a discussion. The previous method can be requested using RNGkind() or RNGversion() if necessary for reproduction of old results. Thanks to Duncan Murdoch for contributing the patch and Gabe Becker for further assistance.

    The output of RNGkind() has been changed to also return the 'kind' used by sample().

CodePudding user response:

3.6 introduced some changes. You can read about them here:

https://stat.ethz.ch/pipermail/r-announce/2019/000641.html

If necessary you can get the same behavior by calling some functions to get results to match previous versions. Look up ?RNGkind or ?RNGversion for more details.

The relevant section from the news file:

The previous method
  can be requested using RNGkind() or RNGversion() if necessary for
  reproduction of old results.
  • Related