Dear R users, inspecting .Random.seed for the Mersenne Twister (MT) I find (many) negative values for the 624 values of the initial state of the generator. It seems to me that this is a bug (an unsigned integer mapped to a signed integer ?), since, to my understanding, the R version of MT should be working with 32-bits unsigned long. Moreover, this prevents starting the generator by setting .Random.seed to user provided values. Could someone please provide some insight to this issue ? Many thanks, Luca Passalacqua> RNGkind('default')> RNGkind()[1] "Mersenne-Twister" "Inversion" > set.seed(1)> .Random.seed [1] 403 624 -169270483 -442010614 -603558397 ...-- Luca Passalacqua Department of Statistics University of Rome "La Sapienza" Viale Regina Elena, 295 00161 Rome (Italy) luca.passalacqua at uniroma1.it -- ________________________________________________________ Le informazioni contenute in questo messaggio di posta elettronica sono strettamente riservate e indirizzate esclusivamente al destinatario. Si prega di non leggere, fare copia, inoltrare a terzi o conservare tale messaggio se non si ? il legittimo destinatario dello stesso. Qualora tale messaggio sia stato ricevuto per errore, si prega di restituirlo al mittente e di cancellarlo permanentemente dal proprio computer. The information contained in this e mail message is strictly confidential and intended for the use of the addressee only.? If you are not the intended recipient, please do not read, copy, forward or store it on your computer. If you have received the message in error, please forward it back to the sender and delete it permanently from your computer system. [[alternative HTML version deleted]]
I am no expert on this specific algorithm, but there is no "32-bit unsigned integer" type in R. Presumably the interpretation of those negative numbers in the C code is as if they were unsigned while R presents them as if they were signed because it cannot do otherwise. AFAIK you need to use set.seed to configure .Random.seed, and you can retrieve and later restore the vectors created this way in the future. As I understand it there exist invalid vectors that cannot arbitrarily be used by this algorithm so generating them yourself is at the very least hard, and possibly could break in future versions of R. On January 9, 2020 1:18:01 AM PST, Luca Passalacqua via R-help <r-help at r-project.org> wrote:>Dear R users, > > inspecting .Random.seed for the Mersenne Twister (MT) I find (many) >negative values for the >624 values of the initial state of the generator. >It seems to me that this is a bug (an unsigned integer mapped to a >signed >integer ?), >since, to my understanding, the R version of MT should be working with >32-bits unsigned long. >Moreover, this prevents starting the generator by setting .Random.seed >to >user provided >values. >Could someone please provide some insight to this issue ? >Many thanks, > >Luca Passalacqua > > >> RNGkind('default')> RNGkind()[1] "Mersenne-Twister" "Inversion" >> set.seed(1)> .Random.seed [1] 403 624 -169270483 >-442010614 -603558397 ...-- Sent from my phone. Please excuse my brevity.
Exactly, from ?.Random.seed: "In the underlying C, .Random.seed[-1] is unsigned; therefore in R .Random.seed[-1] can be negative, due to the representation of an unsigned integer by a signed integer. " and "It can be saved and restored, but should not be altered by the user. " Best, Uwe Ligges On 09.01.2020 16:40, Jeff Newmiller wrote:> I am no expert on this specific algorithm, but there is no "32-bit unsigned integer" type in R. Presumably the interpretation of those negative numbers in the C code is as if they were unsigned while R presents them as if they were signed because it cannot do otherwise. > > AFAIK you need to use set.seed to configure .Random.seed, and you can retrieve and later restore the vectors created this way in the future. As I understand it there exist invalid vectors that cannot arbitrarily be used by this algorithm so generating them yourself is at the very least hard, and possibly could break in future versions of R. > > On January 9, 2020 1:18:01 AM PST, Luca Passalacqua via R-help <r-help at r-project.org> wrote: >> Dear R users, >> >> inspecting .Random.seed for the Mersenne Twister (MT) I find (many) >> negative values for the >> 624 values of the initial state of the generator. >> It seems to me that this is a bug (an unsigned integer mapped to a >> signed >> integer ?), >> since, to my understanding, the R version of MT should be working with >> 32-bits unsigned long. >> Moreover, this prevents starting the generator by setting .Random.seed >> to >> user provided >> values. >> Could someone please provide some insight to this issue ? >> Many thanks, >> >> Luca Passalacqua >> >> >>> RNGkind('default')> RNGkind()[1] "Mersenne-Twister" "Inversion" >>> set.seed(1)> .Random.seed [1] 403 624 -169270483 >> -442010614 -603558397 ... >