random seed

Discussion in 'Python' started by vivek7006@gmail.com, Aug 16, 2005.

  1. Guest

    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
    , Aug 16, 2005
    #1
    1. Advertising

  2. tiissa Guest

    wrote:
    > 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
    tiissa, Aug 16, 2005
    #2
    1. Advertising

  3. Guest

    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.
    , Aug 16, 2005
    #3
  4. Robert Kern Guest

    wrote:
    > 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


    "In the fields of hell where the grass grows high
    Are the graves of dreams allowed to die."
    -- Richard Harter
    Robert Kern, Aug 16, 2005
    #4
  5. Magnus Lycka Guest

    Robert Kern wrote:
    > 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. :)
    Magnus Lycka, Aug 17, 2005
    #5
  6. anil_2009

    Joined:
    May 22, 2009
    Messages:
    1
    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
    >>>
    anil_2009, May 22, 2009
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Leon

    The Best Seed for Random Numbers

    Leon, Nov 8, 2004, in forum: ASP .Net
    Replies:
    10
    Views:
    7,961
    vMike
    Nov 8, 2004
  2. Vumani Dlamini

    random seed when using GSL

    Vumani Dlamini, Apr 21, 2005, in forum: C Programming
    Replies:
    1
    Views:
    1,032
    Ben Pfaff
    Apr 21, 2005
  3. globalrev
    Replies:
    4
    Views:
    739
    Gabriel Genellina
    Apr 20, 2008
  4. NZach

    Problem this random seed()

    NZach, Mar 19, 2013, in forum: Python
    Replies:
    19
    Views:
    149
    NZach
    Mar 19, 2013
  5. Nick Mellor
    Replies:
    7
    Views:
    57
    John Gordon
    Apr 16, 2014
Loading...

Share This Page