RandStream.create

Creates a random number stream with a named generator.

Category: Mathematics > Random Number Generation

Syntax

s = RandStream.create(type)

Creates a stream with the generator type.

s = RandStream.create(type, 'Seed', seed)

Creates it with a given seed.

Description

RandStream.create is the static form of the RandStream constructor. In MATLAB it also builds several independent streams at once with the 'NumStreams' option, which is how parallel code gets non-overlapping sequences; for a single stream it behaves like RandStream(type, ...).

After creating a stream, pass it as the first argument to rand, randn, randi or randperm, or make it the global stream with RandStream.setGlobalStream.

Input arguments

type
Generator name; 'mt19937ar' is the one MatLivre supports.
'Seed'
Nonnegative integer seed.

Output arguments

s
A RandStream object.

Example

Create and draw

s = RandStream.create('mt19937ar', 'Seed', 7);
x = rand(s, 1, 2);
reset(s);
y = rand(s, 1, 2);
isequal(x, y)
Output
ans = logical
   1

Notes

Only 'mt19937ar' is supported, and creating multiple streams with 'NumStreams' is not.

See also

RandStream RandStream.setGlobalStream reset (RandStream) rng