Ask Your Question

random seed

asked 2013-04-16 11:08:28 +0200

Pedro gravatar image

How to start using random() and stop the process and then recover the random generation from the point where it stopped?


  some cycle calling random()


  set_random_seed( ...where??... )
  more steps of some cycle calling random()
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2013-04-16 12:03:14 +0200

ppurka gravatar image

I don't have an answer to your question, which could be interpreted about storing the current random state and then restarting from that state.

On the other hand, if you are not making any calls to any random generator in the intermediate steps, then you don't need to set the random seed to anything. The next random() call should start from exactly where it was stopped.

sage: set_random_seed(0)
sage: [ZZ.random_element() for _ in range(4)]
[-8, 2, 0, 0]
sage: [ZZ.random_element() for _ in range(4)]
[1, -1, 2, 1]

You can see that the random generator starts off from the same point even when I have intermediate computations.

sage: set_random_seed(0)
sage: [ZZ.random_element() for _ in range(4)]
[-8, 2, 0, 0]
sage: integrate(x^2, x)
sage: F.<a> = GF(4,'a')
sage: [ZZ.random_element() for _ in range(4)]
[1, -1, 2, 1]
edit flag offensive delete link more


By "later" I mean few days later and not just the next computation. Maybe this is not an effective mathematical question because random is random at all times (stopping or not). Starting from a seed there's a cycle in generated random number. But maybe that's no important to follow the same cycle if I interrupt the computation. Thanks.

Pedro gravatar imagePedro ( 2013-04-16 12:10:34 +0200 )edit

answered 2013-04-16 11:55:08 +0200

slelievre gravatar image

Would current_randstate help? See the doc for randstate.

edit flag offensive delete link more


I've read but probably I'm missing the answer.

Pedro gravatar imagePedro ( 2013-04-16 12:07:35 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2013-04-16 11:08:28 +0200

Seen: 1,177 times

Last updated: Apr 16 '13