RandStream.create
R2026bCreate statistically independent random number streams
Syntax
Description
creates a single random number stream that uses the uniform random number generator
algorithm specified by s = RandStream.create(generator)generator. The RandStream function is a more concise alternative when you want to create a
single stream.
[
creates s1,s2,...,sn] = RandStream.create(generator,NumStreams=n)n random number streams. These streams are mutually independent,
but they might not be independent of streams created at other times.
Note
Not all generator algorithms support multiple streams. For more information, see
generator.
For example, you can use the multiplicative lagged Fibonacci generator
("mlfg6331_64") or the combined multiple recursive generator
("mrg32k3a") to create multiple streams.
[___] = RandStream.create(
specifies additional options using one or more name-value arguments.generator,Name=Value)
Examples
Input Arguments
Name-Value Arguments
Output Arguments
More About
Tips
Typically, you call RandStream.create once to create multiple
independent streams in a single pass or at the beginning of a MATLAB® session. For example, you can create three independent streams by using
[s1,s2,s3] = RandStream.create("mrg32k3a",NumStreams=3), which returns
three separate RandStream objects. As an alternative, you can use
S = RandStream.create("mrg32k3a",NumStreams=3,CellOutput=true) to return
a 1-by-3 cell array of RandStream objects.
Alternatively, you can create each stream from a separate call to
RandStream.create, but you must specify the appropriate values for
generator, NumStreams, Seed, and
StreamIndices to ensure their independence:
Specify the same values for
generator,NumStreams, andSeedin each case.Specify a different value for
StreamIndiceseach time. Specify values between1and the value ofNumStreams.
For example, create two independent streams by using s1 =
RandStream.create("mrg32k3a",NumStreams=5,Seed=0,StreamIndices=1) and s2
= RandStream.create("mrg32k3a",NumStreams=5,Seed=0,StreamIndices=2).

