필터 지우기
필터 지우기

Create variable number of random streams (unique, deterministic, independent)

조회 수: 4 (최근 30일)
AJ
AJ 2022년 4월 14일
댓글: AJ 2022년 4월 14일
For our simulations, we wish to have repeatable (pseudo-)random number generation.
The problem with using a "global " random stream is that it is possibly shared with other MATLAB processes, which can corrput (make non-repeatable) the random generation.
Now, this is solved in part by the 'NumStreams' argument to RandStream.create, e.g.:
[s1,s2,s3,s4] = RandStream.create('mrg32k3a','NumStreams',4)
This creates four unique, deterministic, independent random number streams.
The problem: The left hand side is fixed at four elements.
The question: How do I generalize this to handle a variable number of random number streams? For example:
[???] = RandStream.create('mrg32k3a','NumStreams',K)
I can think of some ad hoc approaches (e.g. using one stream to generate seeds for the remaining streams) but I worry about true independence of the streams.

채택된 답변

Steven Lord
Steven Lord 2022년 4월 14일
See the "Substreams" and "Restore State of Random Number Generator to Reproduce Output" sections on this documentation page for more information.
  댓글 수: 1
AJ
AJ 2022년 4월 14일
Thanks, glad to know it was right there the whole time. : )
And thanks, Steven, for your plethora of contributions over the years; you've been a constant force of good for as long as I can remember using Answers, and the forum that preceded it.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

AJ
AJ 2022년 4월 14일
With some experimentation, the use of cell arrays is a one solution:
K = 4;
myStreams = cell(1,K);
[myStreams{:}] = RandStream.create('mrg32k3a','NumStreams',K)
I would have preferred a standard array (rather than a cell array), but "Concatenation of RandStream objects is not allowed. Use a cell array to contain multiple objects."

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by