I would like to generate random numbers based on a random seed, for example what numpy.random does if the seed is not specified. But I would also like to print out the initial state, so I can replicate the random numbers. Can I get a human readable or printable version of the initial state? Alternatively, what's a good way to randomly generate an initial state? I could draw an integer with randint and use it as seed. Is this the best way? Josef
josef.pktd@gmail.com wrote:
I would like to generate random numbers based on a random seed, for example what numpy.random does if the seed is not specified. But I would also like to print out the initial state, so I can replicate the random numbers.
Can I get a human readable or printable version of the initial state? Alternatively, what's a good way to randomly generate an initial state?
I could draw an integer with randint and use it as seed. Is this the best way?
Josef
import struct import os seed = struct.unpack ('I', os.urandom (4))[0] print seed
On Wed, Sep 22, 2010 at 10:32 AM, Neal Becker
josef.pktd@gmail.com wrote:
I would like to generate random numbers based on a random seed, for example what numpy.random does if the seed is not specified. But I would also like to print out the initial state, so I can replicate the random numbers.
Can I get a human readable or printable version of the initial state? Alternatively, what's a good way to randomly generate an initial state?
I could draw an integer with randint and use it as seed. Is this the best way?
Josef
import struct import os seed = struct.unpack ('I', os.urandom (4))[0] print seed
os.urandom(4) '\x02\xcf\xd5`' np.array(os.urandom(4)).view(int) array(-452038899) import struct seed = struct.unpack ('I', os.urandom (4))[0] seed 3650333822L np.random.seed(seed) Traceback (most recent call last): File "
", line 1, in <module> np.random.seed(seed) File "mtrand.pyx", line 593, in mtrand.RandomState.seed (numpy\random\mtrand\mtrand.c:4786) OverflowError: long int too large to convert to int
Josef
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
josef.pktd@gmail.com wrote:
On Wed, Sep 22, 2010 at 10:32 AM, Neal Becker
wrote: josef.pktd@gmail.com wrote:
I would like to generate random numbers based on a random seed, for example what numpy.random does if the seed is not specified. But I would also like to print out the initial state, so I can replicate the random numbers.
Can I get a human readable or printable version of the initial state? Alternatively, what's a good way to randomly generate an initial state?
I could draw an integer with randint and use it as seed. Is this the best way?
Josef
import struct import os seed = struct.unpack ('I', os.urandom (4))[0] print seed
os.urandom(4) '\x02\xcf\xd5`' np.array(os.urandom(4)).view(int) array(-452038899) import struct seed = struct.unpack ('I', os.urandom (4))[0] seed 3650333822L np.random.seed(seed) Traceback (most recent call last): File "
", line 1, in <module> np.random.seed(seed) File "mtrand.pyx", line 593, in mtrand.RandomState.seed (numpy\random\mtrand\mtrand.c:4786) OverflowError: long int too large to convert to int
File to fit :) That code was used with my own random number lib based on boost
On Wed, Sep 22, 2010 at 09:27,
I would like to generate random numbers based on a random seed, for example what numpy.random does if the seed is not specified. But I would also like to print out the initial state, so I can replicate the random numbers.
Can I get a human readable or printable version of the initial state?
[~] |13> prng = np.random.RandomState() [~] |14> prng2 = np.random.RandomState() [~] |15> prng.randint(100, size=10) array([74, 62, 56, 94, 86, 59, 69, 94, 42, 18]) [~] |16> prng2.randint(100, size=10) array([21, 58, 34, 55, 9, 81, 45, 3, 93, 62]) [~] |17> prng2.set_state(prng.get_state()) [~] |18> prng.randint(100, size=10) array([37, 57, 2, 0, 68, 9, 75, 88, 11, 7]) [~] |19> prng2.randint(100, size=10) array([37, 57, 2, 0, 68, 9, 75, 88, 11, 7]) [~] |20> prng.get_state() ('MT19937', array([1368120112, 957462593, 2623310617, 4207155283, 446940397, 3506388262, 4104366519, 371500243, 4029407620, 899392379, .... 1843090101, 2484333397, 4085469971, 306955884, 23307203, 1640066622, 48186677, 637144011, 854838500], dtype=uint32), 26, 0, 2.5933437794758841e-288)
Alternatively, what's a good way to randomly generate an initial state?
np.random.RandomState() will do the best thing on each platform. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
On Wed, Sep 22, 2010 at 10:34 AM, Robert Kern
On Wed, Sep 22, 2010 at 09:27,
wrote: I would like to generate random numbers based on a random seed, for example what numpy.random does if the seed is not specified. But I would also like to print out the initial state, so I can replicate the random numbers.
Can I get a human readable or printable version of the initial state?
[~] |13> prng = np.random.RandomState()
[~] |14> prng2 = np.random.RandomState()
[~] |15> prng.randint(100, size=10) array([74, 62, 56, 94, 86, 59, 69, 94, 42, 18])
[~] |16> prng2.randint(100, size=10) array([21, 58, 34, 55, 9, 81, 45, 3, 93, 62])
[~] |17> prng2.set_state(prng.get_state())
[~] |18> prng.randint(100, size=10) array([37, 57, 2, 0, 68, 9, 75, 88, 11, 7])
[~] |19> prng2.randint(100, size=10) array([37, 57, 2, 0, 68, 9, 75, 88, 11, 7])
[~] |20> prng.get_state()
('MT19937', array([1368120112, 957462593, 2623310617, 4207155283, 446940397, 3506388262, 4104366519, 371500243, 4029407620, 899392379, .... 1843090101, 2484333397, 4085469971, 306955884, 23307203, 1640066622, 48186677, 637144011, 854838500], dtype=uint32), 26, 0, 2.5933437794758841e-288)
Alternatively, what's a good way to randomly generate an initial state?
np.random.RandomState() will do the best thing on each platform.
Thanks, I need to think about whether I want to save the full get_state() tuple (or cheat) Josef
-- Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
On Wed, Sep 22, 2010 at 10:48,
On Wed, Sep 22, 2010 at 10:34 AM, Robert Kern
wrote: On Wed, Sep 22, 2010 at 09:27,
wrote: I would like to generate random numbers based on a random seed, for example what numpy.random does if the seed is not specified. But I would also like to print out the initial state, so I can replicate the random numbers.
Can I get a human readable or printable version of the initial state?
[~] |13> prng = np.random.RandomState()
[~] |14> prng2 = np.random.RandomState()
[~] |15> prng.randint(100, size=10) array([74, 62, 56, 94, 86, 59, 69, 94, 42, 18])
[~] |16> prng2.randint(100, size=10) array([21, 58, 34, 55, 9, 81, 45, 3, 93, 62])
[~] |17> prng2.set_state(prng.get_state())
[~] |18> prng.randint(100, size=10) array([37, 57, 2, 0, 68, 9, 75, 88, 11, 7])
[~] |19> prng2.randint(100, size=10) array([37, 57, 2, 0, 68, 9, 75, 88, 11, 7])
[~] |20> prng.get_state()
('MT19937', array([1368120112, 957462593, 2623310617, 4207155283, 446940397, 3506388262, 4104366519, 371500243, 4029407620, 899392379, .... 1843090101, 2484333397, 4085469971, 306955884, 23307203, 1640066622, 48186677, 637144011, 854838500], dtype=uint32), 26, 0, 2.5933437794758841e-288)
Alternatively, what's a good way to randomly generate an initial state?
np.random.RandomState() will do the best thing on each platform.
Thanks, I need to think about whether I want to save the full get_state() tuple (or cheat)
Save the whole thing. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
participants (3)
-
josef.pktd@gmail.com
-
Neal Becker
-
Robert Kern