RandStream.getGlobalStream
Returns the stream used by rand, randn, randi and randperm.
Category: Mathematics > Random Number Generation
Syntax
s = RandStream.getGlobalStream
Returns the current global random stream.
Description
When no stream is passed explicitly, the random functions draw from the global stream. Getting a handle to it lets you read its properties or draw from it directly. The handle refers to the same stream, so drawing through s advances the state seen by plain rand.
rng is the simpler interface to seed and restore the global stream.
Output arguments
s- The global
RandStreamobject.
Example
Inspecting the global stream
rng(5);
g = RandStream.getGlobalStream;
g.Type
class(g)
a = rand(g, 1, 2);
rng(5);
b = rand(1, 2);
isequal(a, b)
Output
ans = 'mt19937ar'
ans = 'RandStream'
ans = logical
1