I need to perform few tests where I use randn
pseudo random number generator. How can I set the seed on my own, so every time I run this test I will get the same results? (yeah, I know it's a little bit weird, but that's the problem).
I've found the RANDSTREAM
object that has the seed
property, but it's read only. Is there any way to use it for seeding the generator?
A random seed (or seed state, or just seed) is a number (or vector) used to initialize a pseudorandom number generator. For a seed to be used in a pseudorandom number generator, it does not need to be random.
For example, “take a number x, add 900 +x, then subtract 52.” In order for the process to start, you have to specify a starting number, x (the seed). Let's take the starting number 77: Add 900 + 77 = 977. Subtract 52 = 925.
The random number generator needs a number to start with (a seed value), to be able to generate a random number. By default the random number generator uses the current system time. Use the seed() method to customize the start number of the random number generator.
What is the significance of random. seed(42) ? It's a pop-culture reference! In Douglas Adams's popular 1979 science-fiction novel The Hitchhiker's Guide to the Galaxy, towards the end of the book, the supercomputer Deep Thought reveals that the answer to the great question of “life, the universe and everything” is 42.
The old way of doing it:
randn('seed',0)
The new way:
s = RandStream('mcg16807','Seed',0) RandStream.setDefaultStream(s)
Note that if you use the new way, rand
and randn
share the same stream so if you are calling both, you may find different numbers being generated compared to the old method (which has separate generators). The old method is still supported for this reason (and legacy code).
See http://www.mathworks.com/help/techdoc/math/bsn94u0-1.html for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With