Re: [sage-support] using random seed for sample() function

2011-03-30 Thread tvn
I see, thanks  -- was not aware Sage also has its own way to set random 
seed.  


-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


Re: [sage-support] using random seed for sample() function

2011-03-28 Thread D. S. McNeil
On Tue, Mar 29, 2011 at 4:00 AM, tvn  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 sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] using random seed for sample() function

2011-03-28 Thread tvn
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 ?  Thanks,  

sage: random.seed(1)
sage: random.random()
0.13436424411240122
sage: sample(range(5),2)
[4, 1]
sage: random.seed(1)
sage: random.random()
0.13436424411240122
sage: sample(range(5),2)
[0, 4]

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org