On Sun, Apr 3, 2011 at 7:01 PM, D. M. Monarres <dmmonar...@gmail.com> wrote: > Was working on some code that required the random shuffling of the order of > a list and noticed that there was both a random() function implemented in > the sage library and a random module in the python standard library. > Importing the latter seems to overwrite the former and I was wondering if > that was done deliberately.
Yes. There is a Sage module sage.misc.prandom that defines very similar random functions as the standard library random function, and *all* of those functions are imported by default. However, the Sage ones play better with the set_random_seed function in Sage. E.g., sage: set_random_seed(0); sage.misc.prandom.randint(0,10) 1 sage: set_random_seed(0); sage.misc.prandom.randint(0,10) 1 sage: set_random_seed(0); sage.misc.prandom.randint(0,10) 1 sage: import random sage: set_random_seed(0); random.randint(0,10) 1 sage: set_random_seed(0); random.randint(0,10) 8 As you can see, if you want to use the set_random_seed function, which works with essential all the different random number generators in Sage (and its components), then you better use sage.misc.prandom, rather than Python's random. Also, for comparison: sage: sage.misc.prandom. sage.misc.prandom.betavariate sage.misc.prandom.paretovariate sage.misc.prandom.choice sage.misc.prandom.randint sage.misc.prandom.current_randstate sage.misc.prandom.random sage.misc.prandom.expovariate sage.misc.prandom.randrange sage.misc.prandom.gammavariate sage.misc.prandom.sample sage.misc.prandom.gauss sage.misc.prandom.shuffle sage.misc.prandom.getrandbits sage.misc.prandom.uniform sage.misc.prandom.lognormvariate sage.misc.prandom.vonmisesvariate sage.misc.prandom.normalvariate sage.misc.prandom.weibullvariate sage: import random sage: random. random.BPF random.division random.random random.LOG4 random.expovariate random.randrange random.NV_MAGICCONST random.gammavariate random.sample random.RECIP_BPF random.gauss random.seed random.Random random.getrandbits random.setstate random.SG_MAGICCONST random.getstate random.shuffle random.SystemRandom random.jumpahead random.triangular random.TWOPI random.lognormvariate random.uniform random.WichmannHill random.normalvariate random.vonmisesvariate random.betavariate random.paretovariate random.weibullvariate random.choice random.randint > > -- > D. M. Monarres > <dmmonar...@gmail.com> > > -- > To post to this group, send an email to sage-devel@googlegroups.com > To unsubscribe from this group, send an email to > sage-devel+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/sage-devel > URL: http://www.sagemath.org > -- William Stein Professor of Mathematics University of Washington http://wstein.org -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org