Folks,
It looks like using "seeds" is being considered "old fashioned" in Matlab 2022b, and there is a warning about it suggesting it will be obsolete soon. We are encouraged to use "rng" function instead, which has only one way to set the seed by using the "default" option. The problem I have with this is that my usage model is such that I want to change seeds and lock them for subsequent runs within the same program instance. I don't see how this is possibly unless I am able to save more than one "default" position. Is there another way to achieve my desired result using a function not targetted for obsolesence?
Thanks,
Kris

댓글 수: 7

Rik
Rik 2023년 1월 27일
What do you mean by locking? You can specify a seed yourself if you want, the example in the documentation for rng shows you how you can do that. You seem to be confused by the syntax rng('default'). It will set the seed to 0 and the generator to twister, but you can set other parameters if you wish.
I am getting this error when using:
>> rng('default')
Error using rand
State must be a double scalar or the output of RAND('twister').
Rik
Rik 2023년 3월 8일
@Tahariet Sharon which Matlab release are you using?
2019b
@Tahariet Sharon: please show us the output of this command:
which rng -all
/Applications/MATLAB_R2022b.app/toolbox/matlab/randfun/rng.m
Rik
Rik 2023년 6월 20일
That is extremely strange. You're using R2019b, but the which command shows that the files used belongs to R2022b.

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

 채택된 답변

Steven Lord
Steven Lord 2023년 1월 27일
It looks like using "seeds" is being considered "old fashioned" in Matlab 2022b, and there is a warning about it suggesting it will be obsolete soon.
Are you referring to this documentation page which has existed for many years now (IIRC since the introduction of rng in release R2011a over ten years ago?) That page describes why those syntaxes are discouraged, and it's not because they "old fashioned" but because they're probably not doing what you think they are.
We are encouraged to use "rng" function instead, which has only one way to set the seed by using the "default" option.
That is incorrect. You can specify a seed and a generator in rng. In fact, with your described usage you probably don't want to specify 'default', you want to explicitly fix both the seed and generator.
rng(1234, 'twister')
x = rand(1)
x = 0.1915
rng(5678, 'threefry')
y = rand(1)
y = 0.1174
rng(1234, 'twister')
z = rand(1)
z = 0.1915
x == z % true
ans = logical
1

댓글 수: 1

Kristoffer Walker
Kristoffer Walker 2023년 1월 30일
편집: Kristoffer Walker 2023년 1월 30일
Thanks for pointing this out. I have been using "help rand" and "help rng" in Matlab to review the features. That is where the "default" option is mentioned, but the usage of the seeds is not as well documented there as in the online version of the help page. Just to be clear, one also uses "seed = rng" to get the current seed, and "rng('shuffle')" to reset it to a random value.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

릴리스

R2022b

질문:

2023년 1월 27일

댓글:

Rik
2023년 6월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by