RandStream - Random number stream
Constructor
RandStream
(RandStream)
Description
Pseudorandom numbers in MATLAB come from one or more random
number streams. The simplest way to generate arrays of random numbers
is to use rand, randn, or randi.
These functions all rely on the same stream of uniform random numbers,
known as the default stream. You can create other stream objects that
act separately from the default stream, and you can use their rand, randi, or randn methods
to generate arrays of random numbers. You can also create a random
number stream and make it the default stream.
To create a single random number stream, use either the RandStream constructor
or the RandStream.create factory
method. To create multiple independent random number streams, use RandStream.create.
stream = RandStream.getDefaultStream returns
the default random number stream, that is, 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. The following
table lists defined properties:
Properties
| Property | Description |
| Type | (Read-only) Generator algorithm used by the stream. The list
of possible generators is given by RandStream.list. |
| Seed | (Read-only) Seed value used to create the stream. |
| NumStreams | (Read-only) Number of streams in the group in which the current
stream was created. |
| StreamIndex | (Read-only) Index of the current stream from among the group
of streams with which it was created. |
| State | Internal state of the generator. You should not depend on the
format of this property. The value you assign to S.State must
be a value read from S.State previously. |
| Substream | Index of the substream to which the stream is currently set.
The default is 1. Multiple substreams are not supported by all generator
types; the multiplicative lagged Fibonacci generator (mlfg6331_64)
and combined multiple recursive generator (mrg32k3a)
support multiple streams. |
| RandnAlg | Algorithm used by randn(s, ...) to generate
normal pseudorandom values. Possible values are 'Ziggurat', 'Polar',
or 'Inversion'. |
| Antithetic | Logical value indicating whether S generates
antithetic pseudorandom values. For uniform values, these are the
usual values subtracted from 1. The default is false. |
| FullPrecision | Logical value indicating whether S generates
values using its full precision. Some generators can create pseudorandom
values faster, but with fewer random bits, if FullPrecision is
false. The default is true. |
Methods
| Method | Description |
| RandStream | Create a random number stream |
| RandStream.create | Create multiple independent random number streams |
| get | Get the properties of a random stream object |
| list | List available random number generator algorithms |
| set | Set random stream property |
| RandStream.getDefaultStream | Get the default random number stream |
| RandStream.setDefaultStream | Set the default random number stream |
| reset | Reset a stream to its initial internal state |
| rand | Pseudorandom numbers from a uniform distribution |
| randn | Pseudorandom numbers from a standard normal distribution |
| randi | Pseudorandom integers from a uniform discrete distribution |
| randperm | Random permutation of a set of values |
See Also
rand, randn, randi, rand (RandStream), randn (RandStream), randi (RandStream)
 | randperm (RandStream) | | RandStream (RandStream) |  |
Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
Get the Interactive Kit