Ask Your Question

# Easy way to get repeatable random number sequences.

Hello!
Tell me please, if there is a simple and easy way to get the same random number sequence multiple times in Sage?
For example, in Python one can use the random.seed() function to set the random seed and then get a random nuber sequence with random.random() function. After that it is easy and obvious to set the random.seed() to the same seed as the first time and get the very same random sequence again.
But how to get such sequences in Sage?

Thanks.

edit retag close merge delete

## 1 Answer

Sort by ยป oldest newest most voted
sage: set_random_seed(10)
sage: initial_seed()
10L
sage: random()
0.96172216248923448
sage: random()
0.4035526020095398
sage: set_random_seed(10)
sage: initial_seed()
10L
sage: random()
0.96172216248923448
sage: random()
0.4035526020095398


And please read the very useful tutorial in help(sage.misc.randstate) for everything you could ever want to know!

more

## Comments

Thank you! In fact, I read that page in tutorial, but didn't quite understand it for some reason. Probably, because I'm slow-witted. :)

( 2011-01-12 09:43:54 +0200 )edit

No worries! And just to be clear, the "initial_seed()" call was just to check that it was indeed set to 10 (because that's what initial_seed returns). It just spits out what the seed is, it doesn't initialize anything, so you don't need to use it in real code. Unless you've set the seed randomly and you want to know what it was set to so you could use the same seed later, etc.

( 2011-01-12 09:50:32 +0200 )edit

## Your Answer

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

Add Answer

## Stats

Asked: 2011-01-12 08:40:26 +0200

Seen: 941 times

Last updated: Jan 12 '11