On Mon, Nov 5, 2012 at 8:08 PM, P Purkayastha <[email protected]> wrote:

> Hi,
>   I have been using the following to generate reproducible sequence of
> random numbers
>
> sage: D = GeneralDiscreteDistribution([**0.5, 0.5]); D.set_seed(0)
> sage: [D.get_random_element() for _ in xrange(5)]
> [1, 0, 0, 1, 0]
> sage: D.set_seed(0)
> sage: [D.get_random_element() for _ in xrange(5)]
> [1, 0, 0, 1, 0]
>
> Why so? Because the set_random_seed(0) call does not set the random seed
> for all random number generators:
>
> sage: D = GeneralDiscreteDistribution([**0.5, 0.5]);
> sage: set_random_seed(0)
> sage: [D.get_random_element() for _ in xrange(5)]
> [1, 0, 0, 0, 0]
> sage: [randint(1,9) for _ in xrange(5)]
> [2, 5, 1, 3, 5]
> sage: set_random_seed(0)
> sage: [D.get_random_element() for _ in xrange(5)]
> [1, 0, 1, 0, 1]
> sage: [randint(1,9) for _ in xrange(5)]
> [2, 5, 1, 3, 5]
>
> So, my question is - is there any "universal" command which can set the
> seed for _all_ random number generators in Sage?


No.  set_random_seed is supposed to be that, but for some reason that I
don't understand it doesn't set Python's own random seed.  I've brought
this up before, though.   Here's the code I use for seeding the random
number generator in my forking sage server (some code from https://salv.us):

    # seed the random number generator(s)
    import sage.all; sage.all.set_random_seed()
    import time; import random; random.seed(time.time())

Nobody's heard in years from the person who wrote Sage's set_random_seed,
so I doubt he'll way in.

 -- William

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
Visit this group at http://groups.google.com/group/sage-support?hl=en.


Reply via email to