[Numpy-discussion] printable random seed ?

josef.pktd@gmai... josef.pktd@gmai...
Wed Sep 22 10:46:40 CDT 2010


On Wed, Sep 22, 2010 at 10:32 AM, Neal Becker <ndbecker2@gmail.com> 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 "<pyshell#182>", 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
>


More information about the NumPy-Discussion mailing list