Re: Problem with 'Random' function
- From: Peter Boettcher <boettcher@xxxxxxxxxx>
- Date: Tue, 08 Jul 2008 08:50:09 -0400
"Nitin Chhabra" <nitin.chhabra@xxxxxx> writes:
Peter Perkins <Peter.PerkinsRemoveThis@xxxxxxxxxxxxx> wrote
in message <g4taf9$mpj$1@xxxxxxxxxxxxxxxxxx>...
Nitin Chhabra wrote:
Here is the output when i write "help randperm" :
help randperm
RANDPERM Random permutation.
RANDPERM(n) is a random permutation of the integers
from 1 to n.
For example, RANDPERM(6) might be [2 4 5 6 1 3].
Note that RANDPERM calls RAND and therefore changes
RAND's state.
See also PERMUTE.
So if I am wrong then help should be modified accordingly. Because
that also writes the same as i stated.
Nitin, there's a big difference between what the help above says, and
explicitly resetting the state of the random number generator before
each call to RAND. There is no good reason that I know of to do the
latter, and in fact, depending on how you do it, doing that could
introduce non- randomness in the output.
Resetting the random number generator is something you
should do
1) (perhaps) once at startup, to get different sequences of values in
different matlab sessions, or
2) to reproduce results for testing or debugging purposes.
Hi Peter,
I think I have confused the thing.Let me clarify it :
What I intended was not to reset the state of random number
generator. But to set the state each time to a value
different from the previous value just to make sure random
number generated is not repeated.
Nitin-
I mean no offense, but you should probably read up on how pseudorandom
number generators work. Here's a primer:
http://en.wikipedia.org/wiki/Pseudorandom_number_generator
Pay special attention to the section on periodicity.
A PRNG generates a sequence of numbers which appear random. The
periodicity is how long that sequence is before it repeats. MATLAB's
Mersenne Twister algorithm generates a VERY long sequence before it
repeats. This is different from repeating one sample, which must be
able to happen if you want independent random samples.
The "seed" of a random number generator can be thought of as an index
into the huge sequence of numbers. And manually setting the seed in
between each sample makes the numbers far less random (you are basically
defeating the entire design of the PRNG). Nor does it prevent repeated
samples.
When RANDPERM says "changes the RAND's state", the point is that it uses
RAND to generate it's random numbers, which advances RAND's PRNG one
sample, which changes the state. The state changes every time you draw
a sample.
Still, you should only ever set the state of a PRNG manually ONCE, at
the beginning of each experiment, for either of two reasons: You want
the PRNG to give you the same sequence each time. Or you want the PRNG
to give you a different sequence each time. After that, let the PRNG do
it's job.
-Peter
.
- Follow-Ups:
- Re: Problem with 'Random' function
- From: Nitin Chhabra
- Re: Problem with 'Random' function
- References:
- Problem with 'Random' function
- From: Ashish Jain
- Re: Problem with 'Random' function
- From: Nitin Chhabra
- Re: Problem with 'Random' function
- From: Walter Roberson
- Re: Problem with 'Random' function
- From: Nitin Chhabra
- Re: Problem with 'Random' function
- From: Walter Roberson
- Re: Problem with 'Random' function
- From: Nitin Chhabra
- Re: Problem with 'Random' function
- From: Peter Perkins
- Re: Problem with 'Random' function
- From: Nitin Chhabra
- Problem with 'Random' function
- Prev by Date: Re: Vectorization for Quadratic Polynomial Regression
- Next by Date: Re: bluring an image with 1D FIR filter
- Previous by thread: Re: Problem with 'Random' function
- Next by thread: Re: Problem with 'Random' function
- Index(es):
Relevant Pages
|
Loading