random seed

V

vivek7006

By default, randomm module uses the timestamp to generate the seed
value. Is it possible to know what that seed value is?

import random
random.random()
# How do I print the current value of the seed?


Thanks
Vivek
 
T

tiissa

By default, randomm module uses the timestamp to generate the seed
value. Is it possible to know what that seed value is?

From a (very) quick glance at the doc [1], I'm not sure you can get it.

But if you want to reuse it later (for a deterministic behaviour), you
can get and set the internal state of the generator (using getstate and
setstate).

[1] http://docs.python.org/lib/module-random.html
 
V

vivek7006

Thanks. I guess I will use the system time and pass it as seed
explicitly. My goal is to replicate the random numbers that I generate
to ensure repeatabilty in the regression test suite that I am trying
to write.
 
R

Robert Kern

Thanks. I guess I will use the system time and pass it as seed
explicitly. My goal is to replicate the random numbers that I generate
to ensure repeatabilty in the regression test suite that I am trying
to write.

In that case you should just pick a single seed yourself instead of
getting it from system time.

random.seed(1234567890)

is traditional and works just fine.

Other favorites:

3141592653589793
2718281828459045

--
Robert Kern
(e-mail address removed)

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
 
M

Magnus Lycka

Robert said:
random.seed(1234567890)

is traditional and works just fine.

Other favorites:

3141592653589793
2718281828459045

Nothing beats 42!
(That was just an exclamation mark in the end, no factorial intended.)

371 is another nice number, since it's its own reverse in hex.

If you liked 3141592653589793, you might also like 113355. :)
 
Joined
May 21, 2009
Messages
1
Reaction score
0
Hello,
I tried following and it does not seem to work. Am I missing something?

Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import random
>>> print random.seed(1234567890)
None
>>> print random.seed(371)
None
>>>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top