RandStream.create
Create random number streams
Class
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)
createsn
random number streams that use the uniform pseudorandom number generator algorithm specified bygentype
. 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 forgentype
or seeChoosing a Random Number Generator有关创erator 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. TheRandStream
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 is1:N , whereN 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 byrandn(年代,…) 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 callRandStream.create
once to create multiple independent streams in a single pass. Alternatively, you can create each stream from separate calls toRandStream.create
, but you must specify the appropriate values forgentype
,'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 between1
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);