On Tue, Mar 29, 2011 at 4:00 AM, tvn <[email protected]> wrote: > I'd like to be able to regenerate samples by feeding a seed value to > random.seed() , but it seems sample() doesn't use this random seed. Is > there a way to do what I want ?
help(sage.misc.randstate) explains a lot of the gory details. set_random_seed() controls the _Sage_ random seed, but I think if you're replacing the random() function with the Python random module (to use random.random() instead of just random()) you're going to have to set both: sage: reset() sage: import random sage: sage: # try just set_random_seed.. sage: set_random_seed(1) sage: random.random() 0.84743373693723267 sage: sample(range(5),2) [4, 2] sage: sage: set_random_seed(1) sage: random.random() 0.76377461897661403 sage: # that didn't work.. sage: sample(range(5),2) [4, 2] sage: # but this did! sage: sage: # so we have to use both.. sage: set_random_seed(1) # for Sage sage: random.seed(1) # for Python random module sage: random.random() 0.13436424411240122 sage: sample(range(5),2) [4, 2] sage: sage: set_random_seed(1) # for Sage sage: random.seed(1) # for Python random module sage: random.random() 0.13436424411240122 sage: sample(range(5),2) [4, 2] Doug -- Department of Earth Sciences University of Hong Kong -- To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
