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.Wed, 12 Jan 2011 02:50:32 -0600Easy way to get repeatable random number sequences.http://ask.sagemath.org/question/7863/easy-way-to-get-repeatable-random-number-sequences/Hello!
Tell me please, if there is a simple and easy way to get the same random number sequence multiple times in Sage?
For example, in Python one can use the random.seed() function to set the random seed and then get a random nuber sequence with random.random() function. After that it is easy and obvious to set the random.seed() to the same seed as the first time and get the very same random sequence again.
But how to get such sequences in Sage?
Thanks.Wed, 12 Jan 2011 01:40:26 -0600http://ask.sagemath.org/question/7863/easy-way-to-get-repeatable-random-number-sequences/Answer by DSM for <p>Hello! <br/>
Tell me please, if there is a simple and easy way to get the same random number sequence multiple times in Sage? <br/>
For example, in Python one can use the random.seed() function to set the random seed and then get a random nuber sequence with random.random() function. After that it is easy and obvious to set the random.seed() to the same seed as the first time and get the very same random sequence again. <br/>
But how to get such sequences in Sage?</p>
<p>Thanks.</p>
http://ask.sagemath.org/question/7863/easy-way-to-get-repeatable-random-number-sequences/?answer=11964#post-id-11964<pre><code>sage: set_random_seed(10)
sage: initial_seed()
10L
sage: random()
0.96172216248923448
sage: random()
0.4035526020095398
sage: set_random_seed(10)
sage: initial_seed()
10L
sage: random()
0.96172216248923448
sage: random()
0.4035526020095398
</code></pre>
And please read the very useful tutorial in <a href="http://www.sagemath.org/doc/reference/sage/misc/randstate.html">help(sage.misc.randstate)</a> for everything you could ever want to know!
Wed, 12 Jan 2011 01:46:11 -0600http://ask.sagemath.org/question/7863/easy-way-to-get-repeatable-random-number-sequences/?answer=11964#post-id-11964Comment by v_2e for <pre><code>sage: set_random_seed(10)
sage: initial_seed()
10L
sage: random()
0.96172216248923448
sage: random()
0.4035526020095398
sage: set_random_seed(10)
sage: initial_seed()
10L
sage: random()
0.96172216248923448
sage: random()
0.4035526020095398
</code></pre>
<p>And please read the very useful tutorial in <a href="http://www.sagemath.org/doc/reference/sage/misc/randstate.html">help(sage.misc.randstate)</a> for everything you could ever want to know! </p>
http://ask.sagemath.org/question/7863/easy-way-to-get-repeatable-random-number-sequences/?comment=22294#post-id-22294Thank you! In fact, I read that page in tutorial, but didn't quite understand it for some reason. Probably, because I'm slow-witted. :)Wed, 12 Jan 2011 02:43:54 -0600http://ask.sagemath.org/question/7863/easy-way-to-get-repeatable-random-number-sequences/?comment=22294#post-id-22294Comment by DSM for <pre><code>sage: set_random_seed(10)
sage: initial_seed()
10L
sage: random()
0.96172216248923448
sage: random()
0.4035526020095398
sage: set_random_seed(10)
sage: initial_seed()
10L
sage: random()
0.96172216248923448
sage: random()
0.4035526020095398
</code></pre>
<p>And please read the very useful tutorial in <a href="http://www.sagemath.org/doc/reference/sage/misc/randstate.html">help(sage.misc.randstate)</a> for everything you could ever want to know! </p>
http://ask.sagemath.org/question/7863/easy-way-to-get-repeatable-random-number-sequences/?comment=22293#post-id-22293No worries! And just to be clear, the "initial_seed()" call was just to check that it was indeed set to 10 (because that's what initial_seed returns). It just spits out what the seed is, it doesn't initialize anything, so you don't need to use it in real code. Unless you've set the seed randomly and you want to know what it was set to so you could use the same seed later, etc.Wed, 12 Jan 2011 02:50:32 -0600http://ask.sagemath.org/question/7863/easy-way-to-get-repeatable-random-number-sequences/?comment=22293#post-id-22293