Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

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

PropertyDescription
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.
StateInternal 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.
SubstreamIndex 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.
RandnAlgAlgorithm used by randn(s, ...) to generate normal pseudorandom values. Possible values are 'Ziggurat', 'Polar', or 'Inversion'.
AntitheticLogical value indicating whether S generates antithetic pseudorandom values. For uniform values, these are the usual values subtracted from 1. The default is false.
FullPrecisionLogical 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

MethodDescription
RandStreamCreate a random number stream
RandStream.createCreate multiple independent random number streams
getGet the properties of a random stream object
listList available random number generator algorithms
setSet random stream property
RandStream.getDefaultStreamGet the default random number stream
RandStream.setDefaultStreamSet the default random number stream
resetReset a stream to its initial internal state
randPseudorandom numbers from a uniform distribution
randnPseudorandom numbers from a standard normal distribution
randiPseudorandom integers from a uniform discrete distribution
randpermRandom permutation of a set of values

See Also

rand, randn, randi, rand (RandStream), randn (RandStream), randi (RandStream)

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS