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]]

