Accelerating the pace of engineering and science

# Documentation Center

• Trial Software

# RandStream.create

Create random number streams

RandStream

## Syntax

[s1,s2,...] = RandStream.create('gentype','NumStreams',n)
s = RandStream.create('gentype')
[ ... ] = RandStream.create('gentype', Name, Value,...)

## Description

[s1,s2,...] = RandStream.create('gentype','NumStreams',n) creates n random number streams that use the uniform pseudorandom number generator algorithm specified by gentype. The streams are independent in a pseudorandom sense. The streams are not necessarily independent from streams created at other times. RandStream.list returns all possible values for gentype or see Choosing a Random Number Generator in the MATLAB® Mathematics documentation for details on generator algorithms.

 Note:   Multiple streams are not supported by all generator types. Use either the multiplicative lagged Fibonacci generator (mlfg6331_64) or the combined multiple recursive generator (mrg32k3a) to create multiple streams.

s = RandStream.create('gentype') creates a single random stream. The RandStream constructor is a more concise alternative when you need to create a single stream.

[ ... ] = RandStream.create('gentype', Name, Value,...) allows you to specify optional Name, Value pairs to control creation of the stream. The parameters are:

 NumStreams Total number of streams of this type that will be created across sessions or labs. Default is 1. StreamIndices Stream indices that should be created in this call. Default is 1:N, where N is the value given with the 'NumStreams' parameter. Seed Nonnegative scalar integer with which to initialize all streams. Default is 0. Seeds must be an integer between 0 and 232 − 1 or 'shuffle' to create a seed based on the current time. NormalTransform Transformation algorithm used by randn(S, ...) to generate normal pseudorandom values. Options are 'Ziggurat', 'Polar', or 'Inversion'. CellOutput Logical flag indicating whether or not to return the stream objects as elements of a cell array. Default is false.

Typically, you call RandStream.create once to create multiple independent streams in a single pass. Alternatively, you can create each stream from separate calls to RandStream.create, but you must specify the appropriate values for gentype, 'NumStreams', 'Seed', and 'StreamIndices' to ensure their independence:

• Specify the same set of values for gentype, 'NumStreams', and 'Seed' in each case.

• Specify a different value for 'StreamIndices' that is between 1 and the 'NumStreams' value in each case.

## 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 one stream from a set of three independent streams and designate it as the global stream.

```s2 = RandStream.create('mrg32k3a','NumStreams',3,'StreamIndices',2);
RandStream.setGlobalStream(s2);
```