[Numpy-discussion] printable random seed ?

Robert Kern robert.kern@gmail....
Wed Sep 22 09:34:50 CDT 2010


On Wed, Sep 22, 2010 at 09:27,  <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?

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


More information about the NumPy-Discussion mailing list