- •In matlab 7.7, use the default stream as described in randstream.
- •Vector and covariance matrix.
- •Is usually not desirable to do this more than once per matlab session.
- •Independent random number streams, use RandStream.Create.
- •Is usually not desirable to do this more than once per matlab session.
- •Initialize all streams. Default is 0.
Independent random number streams, use RandStream.Create.
STREAM = RandStream.getDefaultStream returns the default random number
stream, i.e., the one currently used by the RAND, RANDI, and RANDN
functions.
PREVSTREAM = RandStream.setDefaultStream(STREAM) returns the current default
stream, and designates the random number stream STREAM as the new default to
be used by the RAND, RANDI, and RANDN functions.
A random number stream S has properties that control its behavior. Access or
assign to a property using P = S.Property or S.Property = P.
RandStream properties:
Type - (Read-only) identifies the type of generator algorithm
used by the stream.
Seed - (Read-only) the seed value used to create the stream.
NumStreams - (Read-only) the number of streams created at the same
time as the stream.
StreamIndex - (Read-only) the stream's index among the group of streams
in which it was created.
State - the internal state of the generator. You should not depend
on the format of this property, or attempt to improvise a
property value. The value you assign to S.State must be a
value read from S.State previously. Use RESET to return a
stream to a predictable state without having previously read
from the State property.
Substream - the index of the substream to which the stream is
currently set. The default is 1. Multiple substreams are
not supported by all generator types.
RandnAlg - the current algorithm used by RANDN(S, ...) to generate
normal pseudorandom values, one of 'Ziggurat' (the
default), 'Polar', or 'Inversion'.
Antithetic - a logical value indicating whether S generates antithetic
uniform pseudorandom values, that is, the usual values
subtracted from 1. The default is false.
FullPrecision - a logical value indicating whether S generates values
using its full precision. Some generators are able to
create pseudorandom values faster, but with fewer random
bits, if FullPrecision is false. The default is true.
The sequence of pseudorandom numbers produced by a random number stream S is
determined by the internal state of its random number generator. Saving and
restoring the generator's internal state via the 'State' property allows you
to reproduce output.
Examples:
Create three independent streams:
[s1,s2,s3] = RandStream.create('mrg32k3a','NumStreams',3);
r1 = rand(s1,100000,1); r2 = rand(s2,100000,1); r3 = rand(s3,100000,1);
corrcoef([r1,r2,r3])
Create only one stream from a set of three independent streams:
s2 = RandStream.create('mrg32k3a','NumStreams',3,'StreamIndices',2);
Reset the generator for the default stream that underlies RAND, RANDI,
and RANDN back to the beginning to reproduce previous results:
reset(RandStream.getDefaultStream);
Save and restore the default stream's state to reproduce the output of
RAND:
defaultStream = RandStream.getDefaultStream;
savedState = defaultStream.State;
u1 = rand(1,5)
defaultStream.State = savedState;
u2 = rand(1,5) % contains exactly the same values as u1
Return RAND, RANDI, and RANDN to their default initial settings:
s = RandStream.create('mt19937ar','seed',5489);
RandStream.setDefaultStream(s);
Replace the default stream with a stream whose seed is based on CLOCK, so
RAND will return different values in different MATLAB sessions. NOTE: It