Is set_random_seed supposed to control the Python random number generator? Are there two "standard" random number generators in Sage? I am using the "shuffle" command to (pseudo-randomly) rearrange the elements of a list. From the Sage command line it works fine.
sage: set_random_seed(9) sage: shuffle(t1) sage: t1 [1, 8, 7, 5, 9, 2, 4, 3, 6] sage: sage: set_random_seed(9) sage: sage: shuffle(t1) sage: sage: t1 [1, 8, 7, 5, 9, 2, 4, 3, 6] But in a Python script I imported shuffle from the random module, equivalent to the following code from the command line. sage: from random import shuffle as pyshuffle sage: set_random_seed(9) sage: t1 = [1,2,3,4,5,6,7,8,9] sage: pyshuffle(t1) sage: t1 [8, 5, 2, 1, 7, 9, 3, 4, 6] sage: set_random_seed(9) sage: t1 = [1,2,3,4,5,6,7,8,9] sage: pyshuffle(t1) sage: t1 [4, 2, 3, 1, 9, 8, 6, 7, 5] Obviously, set_random_seed is not controlling this PRNG. From shuffle? I see that the shuffle function comes from sage/misc/ prandom.py, with default random number generator sage.misc.random. On the other hand, (from pyshuffle?) I see that pyshuffle is from a Python directory random.py and says the default underlying PRNG is random.random. The workaround for me is simple: import shuffle from prandom instead of random. But the larger questions remain, is this behavior expected? Is it correct? Thanks! - Ryan On Oct 11, 12:52 am, Carl Witty <[EMAIL PROTECTED]> wrote: > On Oct 10, 5:45 pm, [EMAIL PROTECTED] wrote: > > > Ryan Hinton wrote: > > > Jason, > > > > I saw a suggestion recently on the sage list to set the random seed at > > > the beginning of eachdoctestso previously "random" outputs could be > > > tested. I'm writing some 'pick a random member from this (very large) > > > set' routines, so I could use this functionality. Is it in yet? How > > > can I set the random seed (inside mydoctest)? > > > > Thanks! > > > I think Carl Witty wrote this functionality (I've CCd him). I think it > > is in now, but he knows the details of how to use it. > > Quick summary: > > The random seed is automatically set at the beginning of each > docstring. If you're using the standard Sage random number routines > (like ZZ.random_element(), or the combinatorics random elements, > etc.), then you shouldn't have to do anything to make yourdoctest > repeatable. > > If you do want to set a random seed inside your docstring (or at the > Sage command line), use > > sage: set_random_seed(0) > > (or pick another number instead of the 0). > > For more details, there's about 400 lines of documentation at the top > of sage/misc/randstate.pyx; I don't want to repeat it all here :) > > Carl --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---