how to close rng 'default' after using it once in a same program

조회 수: 4 (최근 30일)
RAJ DATTA
RAJ DATTA 2019년 9월 23일
댓글: Adam Danz 2019년 10월 1일
Suppose, there is a scenario where I am using random number generator(rand(n,1)) which I need to fix for the values of a variable for a loop. So, I am using the command rng 'default'. Again in the same program I need to vary the random numbers in some other loops. But for For this I need to stop rng 'default ' command. Can anybody tell me how to do this?
Thanks in advance.
  댓글 수: 2
Adam Danz
Adam Danz 2019년 9월 23일
편집: Adam Danz 2019년 9월 24일
I don't recommend setting rng('default') within a loop, if that's what you're doing. That defeats the purpose of using a random process since every iteration would have the same sequence of random numbers. If you need to keep track of the random number generator seed for each iteration of a loop, you can store it like this.
n = 5
rngState = [];
for i = 1:n
rngState = [rngState; rng()];
% Your code here
end
seeds = [rngState.Seed]
Adam Danz
Adam Danz 2019년 10월 1일
@RAJ DATTA, if you was rng('shuffle') not the answer you were looking for? Maybe there's a different interpreptation of "For this I need to stop rng 'default ' command."

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

답변 (1개)

Adam Danz
Adam Danz 2019년 9월 23일
편집: Adam Danz 2019년 9월 25일
"For this I need to stop rng 'default ' command. Can anybody tell me how to do this? "
rng('shuffle')
will re-seed the random number generator based on the current time.
For more info:

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by