This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Set global random number stream


prevstream = RandStream.setGlobalStream(stream)


prevstream = RandStream.setGlobalStream(stream) designates the random number stream, specified as stream, to be the global stream that the rand, randi, and randn functions draw values from. It returns the previous global random number stream as prevstream.

rand, randi, and randn all rely on the same stream of uniform pseudorandom numbers, known as the global stream. rand draws one value from that stream to generate each uniform value it returns. randi draws one uniform value from that stream to generate each integer value it returns. And randn draws one or more uniform values to generate each normal value it returns. Note that there are also rand, randi, and randn methods for which you specify a specific random stream from which to draw values.


The rng function is a shorter alternative for many common uses of RandStream.setGlobalStream.

Was this topic helpful?