ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 16 Apr 2013 05:10:34 -0500random seedhttp://ask.sagemath.org/question/10029/random-seed/How to start using random() and stop the process and then recover the random generation from the point where it stopped?
Example
set_random_seed(0)
some cycle calling random()
later
set_random_seed( ...where??... )
more steps of some cycle calling random()
Tue, 16 Apr 2013 04:08:28 -0500http://ask.sagemath.org/question/10029/random-seed/Answer by slelievre for <p>How to start using random() and stop the process and then recover the random generation from the point where it stopped?</p>
<p>Example</p>
<pre><code> set_random_seed(0)
some cycle calling random()
</code></pre>
<p>later</p>
<pre><code> set_random_seed( ...where??... )
more steps of some cycle calling random()
</code></pre>
http://ask.sagemath.org/question/10029/random-seed/?answer=14794#post-id-14794Would `current_randstate` help?
See the [doc for randstate](http://www.sagemath.org/doc/reference/misc/sage/misc/randstate.html).Tue, 16 Apr 2013 04:55:08 -0500http://ask.sagemath.org/question/10029/random-seed/?answer=14794#post-id-14794Comment by Pedro for <p>Would <code>current_randstate</code> help?
See the <a href="http://www.sagemath.org/doc/reference/misc/sage/misc/randstate.html">doc for randstate</a>.</p>
http://ask.sagemath.org/question/10029/random-seed/?comment=17884#post-id-17884I've read but probably I'm missing the answer.Tue, 16 Apr 2013 05:07:35 -0500http://ask.sagemath.org/question/10029/random-seed/?comment=17884#post-id-17884Answer by ppurka for <p>How to start using random() and stop the process and then recover the random generation from the point where it stopped?</p>
<p>Example</p>
<pre><code> set_random_seed(0)
some cycle calling random()
</code></pre>
<p>later</p>
<pre><code> set_random_seed( ...where??... )
more steps of some cycle calling random()
</code></pre>
http://ask.sagemath.org/question/10029/random-seed/?answer=14795#post-id-14795I don't have an answer to your question, which could be interpreted about storing the current random state and then restarting from that state.
On the other hand, if you are not making any calls to any random generator in the intermediate steps, then you don't need to set the random seed to anything. The next random() call should start from exactly where it was stopped.
sage: set_random_seed(0)
sage: [ZZ.random_element() for _ in range(4)]
[-8, 2, 0, 0]
sage: [ZZ.random_element() for _ in range(4)]
[1, -1, 2, 1]
You can see that the random generator starts off from the same point even
when I have intermediate computations.
sage: set_random_seed(0)
sage: [ZZ.random_element() for _ in range(4)]
[-8, 2, 0, 0]
sage: integrate(x^2, x)
1/3*x^3
sage: F.<a> = GF(4,'a')
sage: [ZZ.random_element() for _ in range(4)]
[1, -1, 2, 1]
Tue, 16 Apr 2013 05:03:14 -0500http://ask.sagemath.org/question/10029/random-seed/?answer=14795#post-id-14795Comment by Pedro for <p>I don't have an answer to your question, which could be interpreted about storing the current random state and then restarting from that state.</p>
<p>On the other hand, if you are not making any calls to any random generator in the intermediate steps, then you don't need to set the random seed to anything. The next random() call should start from exactly where it was stopped.</p>
<pre><code>sage: set_random_seed(0)
sage: [ZZ.random_element() for _ in range(4)]
[-8, 2, 0, 0]
sage: [ZZ.random_element() for _ in range(4)]
[1, -1, 2, 1]
</code></pre>
<p>You can see that the random generator starts off from the same point even
when I have intermediate computations.</p>
<pre><code>sage: set_random_seed(0)
sage: [ZZ.random_element() for _ in range(4)]
[-8, 2, 0, 0]
sage: integrate(x^2, x)
1/3*x^3
sage: F.<a> = GF(4,'a')
sage: [ZZ.random_element() for _ in range(4)]
[1, -1, 2, 1]
</code></pre>
http://ask.sagemath.org/question/10029/random-seed/?comment=17883#post-id-17883By "later" I mean few days later and not just the next computation. Maybe this is not an effective mathematical question because random is random at all times (stopping or not). Starting from a seed there's a cycle in generated random number. But maybe that's no important to follow the same cycle if I interrupt the computation. Thanks.Tue, 16 Apr 2013 05:10:34 -0500http://ask.sagemath.org/question/10029/random-seed/?comment=17883#post-id-17883