From: Aaron on
The Matlab documentation says that RAND and RANDN maintain different states, and therefore resetting the seed of one does not affect the other. Do all other random functions in Matlab use these two to generate their output? For example, POISSRND, BINORND, EXPRND.

In other words, if I set random seeds to RAND and RANDN, will this cover all other random functions?

Thanks!
Aaron
From: Rogelio on
"Aaron" <rasputin465.nospam(a)hotmail.com> wrote in message <i3gt4s$nu7$1(a)fred.mathworks.com>...
> The Matlab documentation says that RAND and RANDN maintain different states, and therefore resetting the seed of one does not affect the other. Do all other random functions in Matlab use these two to generate their output? For example, POISSRND, BINORND, EXPRND.
>
> In other words, if I set random seeds to RAND and RANDN, will this cover all other random functions?
>
> Thanks!
> Aaron

I am not sure about your question, but I beleive that many random generator functions in matlab use the same 'core code' to generate a random uniform distributed variable and based on that one generate the possion or the binomial, variable for instance. You can always check that by yourself, by setting the seed for 'randn' and generate an other random number, for instance a poisson, and see if you get the same number after setting the seed.
From: Tom Lane on
> The Matlab documentation says that RAND and RANDN maintain different
> states, and therefore resetting the seed of one does not affect the other.
> Do all other random functions in Matlab use these two to generate their
> output? For example, POISSRND, BINORND, EXPRND.

Aaron, take a look at the table at the bottom of this page:

http://www.mathworks.com/access/helpdesk/help/toolbox/stats/f4218.html

In more recent versions of MATLAB that include the RandStream class, most
random streams use the same state for RAND and RANDN, though.

-- Tom

From: Peter Perkins on
On 8/6/2010 7:54 AM, Aaron wrote:
> The Matlab documentation says that RAND and RANDN maintain different
> states, and therefore resetting the seed of one does not affect the
> other.

That would have to be a version of MATLAB prior to R2008b. Since 8b,
the help for RAND and RANDN have said something similar to this:

Compatibility Note: In versions of MATLAB prior to 7.7, you controlled
the internal state of the random number stream used by RANDN by calling
RANDN directly with the 'seed' or 'state' keywords. That syntax is
still supported for backwards compatibility, but is deprecated.
Beginning in MATLAB 7.7, use the default stream as described in
RANDSTREAM.

The sequence of numbers produced by RANDN is determined by the internal
state of the uniform pseudorandom number generator that underlies RAND,
RANDI, and RANDN. RANDN uses one or more uniform values from that
default stream to generate each normal value. Control the default
stream using its properties and methods. See RANDSTREAM for details
about the default stream.

So, rand and randn do not maintain different states unless you are using
a version of MATLAB prior to R2008b. You can reseed the random number
generator in a couple of different ways, the simplest of which is

reset(RandStream.getDefaultStream,seed)

The old syntaxes you're asking about (e.g., rand('twister',1)) continue
to work as they always have, but are not recommended.

> Do all other random functions in Matlab use these two to generate
> their output? For example, POISSRND, BINORND, EXPRND.

All of the random number functions, including things like RANDPERM and
SPRAND in MATLAB itself, and things like POISSRND and BINORND in the
Statistics Toolbox, rely on one of RAND, RANDN, or RANDI. So in current
versions, there's only one underlying stream of random numbers to worry
about (unless you've executed one of those old commands, in which case
the old behavior kicks in).

In earlier versions, you can look at the code (e.g., RANDPERM uses
RAND), or in this table

http://www.mathworks.com/access/helpdesk/help/toolbox/stats/f4218.html#bqtuw3l

to see what uses what (e.g., POISSRND uses both).

Hope this helps.