Could someone please suggest a method to store the current random seed. I'm having trouble understanding how to correctly use set.seed and .Random.seed. Specifically, I have the following code that crashes: set.seed(seed) for(i in 1:10){ print( runif(1)) } To get around this I need to split the number of iterations into chunks: set.seed(seed) for(i in 1:5){ print(runif(1)) new.seed<-.Random.seed } set.seed(new.seed) for(i in 6:10){ print(runif(1)) } When I compare the sequence of numbers from the single run to the sequence from the chunked code they don't match. Is the .Random.seed argument in the wrong position or is there another way to accomplish this? ------------------------------------------------------- Caitlyn Ellerbe Division of Biostatistics Department of Public Health Medical University of South Carolina [[alternative HTML version deleted]]
"Crashes" is not a clear description. When I execute the statement: set.seed(seed) I get the error Error in set.seed(seed) : object 'seed' not found which makes sense because there is no variable defined that is called "seed". Choose a literal value like 42: set.seed(42) or define the variable seed <- 42 set.seed(seed) and you should not get that error. If you get a different error message, then give us a better clue how to reproduce it. (Also, please post plain text email as the Posting Guide requests. You have read that, right?) --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. "Ellerbe, Caitlyn Nicole" <ellerbcn at musc.edu> wrote:>Could someone please suggest a method to store the current random seed. >I'm having trouble understanding how to correctly use set.seed and >.Random.seed. > >Specifically, I have the following code that crashes: > > > >set.seed(seed) > >for(i in 1:10){ > > print( runif(1)) > >} > > > >To get around this I need to split the number of iterations into >chunks: > > > >set.seed(seed) > >for(i in 1:5){ > >print(runif(1)) > >new.seed<-.Random.seed > >} > > > >set.seed(new.seed) > >for(i in 6:10){ > >print(runif(1)) > >} > > > >When I compare the sequence of numbers from the single run to the >sequence from the chunked code they don't match. Is the .Random.seed >argument in the wrong position or is there another way to accomplish >this? > >------------------------------------------------------- >Caitlyn Ellerbe > >Division of Biostatistics >Department of Public Health >Medical University of South Carolina > > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at r-project.org mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.
By crash, I mean that it shuts the program and no error message is provided. However, my question is more general - how to get the two versions of code below to return the same string of random numbers. The code provided will run without incident and is only provided to make the problem clear. The true code that causes the crash isn't necessary, only that I need to be able to split it into smaller chunks while maintaining the integrity of the random sequence even if the program closes and all information is lost. -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Ellerbe, Caitlyn Nicole Sent: Wednesday, May 08, 2013 2:06 PM To: r-help at R-project.org Subject: [R] Correctly Setting New Seed Could someone please suggest a method to store the current random seed. I'm having trouble understanding how to correctly use set.seed and .Random.seed. Specifically, I have the following code that crashes: set.seed(seed) for(i in 1:10){ print( runif(1)) } To get around this I need to split the number of iterations into chunks: set.seed(seed) for(i in 1:5){ print(runif(1)) new.seed<-.Random.seed } set.seed(new.seed) for(i in 6:10){ print(runif(1)) } When I compare the sequence of numbers from the single run to the sequence from the chunked code they don't match. Is the .Random.seed argument in the wrong position or is there another way to accomplish this? ------------------------------------------------------- Caitlyn Ellerbe Division of Biostatistics Department of Public Health Medical University of South Carolina [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
I was wondering about that code. It seemed to run alright for me. We really need to see the code and hopefully the data, or a,sample thereof, that is causing the actual crash. Prefereably cut out anything that is not causing the problem and ship us the bare minimum of code. http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example Thanks John Kane Kingston ON Canada> -----Original Message----- > From: ellerbcn at musc.edu > Sent: Wed, 8 May 2013 14:50:42 -0400 > To: ellerbcn at musc.edu, r-help at r-project.org > Subject: Re: [R] Correctly Setting New Seed > > By crash, I mean that it shuts the program and no error message is > provided. However, my question is more general - how to get the two > versions of code below to return the same string of random numbers. The > code provided will run without incident and is only provided to make the > problem clear. The true code that causes the crash isn't necessary, only > that I need to be able to split it into smaller chunks while maintaining > the integrity of the random sequence even if the program closes and all > information is lost. > > -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] > On Behalf Of Ellerbe, Caitlyn Nicole > Sent: Wednesday, May 08, 2013 2:06 PM > To: r-help at R-project.org > Subject: [R] Correctly Setting New Seed > > Could someone please suggest a method to store the current random seed. > I'm having trouble understanding how to correctly use set.seed and > .Random.seed. > > Specifically, I have the following code that crashes: > > > > set.seed(seed) > > for(i in 1:10){ > > print( runif(1)) > > } > > > > To get around this I need to split the number of iterations into chunks: > > > > set.seed(seed) > > for(i in 1:5){ > > print(runif(1)) > > new.seed<-.Random.seed > > } > > > > set.seed(new.seed) > > for(i in 6:10){ > > print(runif(1)) > > } > > > > When I compare the sequence of numbers from the single run to the > sequence from the chunked code they don't match. Is the .Random.seed > argument in the wrong position or is there another way to accomplish > this? > > ------------------------------------------------------- > Caitlyn Ellerbe > > Division of Biostatistics > Department of Public Health > Medical University of South Carolina > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.____________________________________________________________ GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM?, MSN? Messenger, Yahoo!? Messenger, ICQ?, Google Talk? and most webmails
This approach gives the same results:> set.seed(1) > for (i in 1:10) print(runif(1))[1] 0.2655087 [1] 0.3721239 [1] 0.5728534 [1] 0.9082078 [1] 0.2016819 [1] 0.8983897 [1] 0.9446753 [1] 0.6607978 [1] 0.629114 [1] 0.06178627> > set.seed(1) > for (i in 1:5) print(runif(1))[1] 0.2655087 [1] 0.3721239 [1] 0.5728534 [1] 0.9082078 [1] 0.2016819> for (i in 6:10) print(runif(1))[1] 0.8983897 [1] 0.9446753 [1] 0.6607978 [1] 0.629114 [1] 0.06178627>On Wed, May 8, 2013 at 2:06 PM, Ellerbe, Caitlyn Nicole <ellerbcn@musc.edu>wrote:> Could someone please suggest a method to store the current random seed. > I'm having trouble understanding how to correctly use set.seed and > .Random.seed. > > Specifically, I have the following code that crashes: > > > > set.seed(seed) > > for(i in 1:10){ > > print( runif(1)) > > } > > > > To get around this I need to split the number of iterations into chunks: > > > > set.seed(seed) > > for(i in 1:5){ > > print(runif(1)) > > new.seed<-.Random.seed > > } > > > > set.seed(new.seed) > > for(i in 6:10){ > > print(runif(1)) > > } > > > > When I compare the sequence of numbers from the single run to the sequence > from the chunked code they don't match. Is the .Random.seed argument in the > wrong position or is there another way to accomplish this? > > ------------------------------------------------------- > Caitlyn Ellerbe > > Division of Biostatistics > Department of Public Health > Medical University of South Carolina > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. [[alternative HTML version deleted]]