How do I ensure random generates different samples each trial?

조회 수: 2(최근 30일)
I fit data to a normal distribution and then sample from that distribution:
%[...]
normal.x = fitdist(InterfractionalMotion.x,'Normal');
normal.y = fitdist(InterfractionalMotion.y,'Normal');
normal.z = fitdist(InterfractionalMotion.z,'Normal');
%[...]
%[excerpt of a function called from inside a loop processing data per patient]
RandomMotion.x = cmtomm*random(normal.x,1,NoFractions);
RandomMotion.y = cmtomm*random(normal.y,1,NoFractions);
RandomMotion.z = cmtomm*random(normal.z,1,NoFractions);
I repeated the 'random' command to sample random motion for each patient. Now I have been asked to conduct another trial using different random numbers, i.e. another random sampling from the same fit distributions.
I recall reading something about 'random number seeds' previously. Given P patients with S samples each, is there some inherent order so that the same set of random numbers S will be called for a different patient? Do I need to do something to ensure that different random samples are taken, such as specify some different seed? The random help documentation does not specify any optional command regarding seeding, so I wonder if it is fine to simply execute the script again.
The article " Random Numbers in MATLAB " emphasizes the need to manage the random number seed, but it is not clear if random sampling from a distribution follows the same mechanism as random number generation. Presumably it does, but I wish to verify.
  댓글 수: 1
Daniel Bridges
Daniel Bridges 2018년 2월 20일
" Generate Random Numbers That Are Different " appears to answer this question, but I'm not sure if random sampling is included in their discussion of random number generators like rand.

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

답변(1개)

Jos (10584)
Jos (10584) 2018년 2월 20일
Executing rand (or random or randi) will return new random numbers, uncorrelated to previously retrieved numbers (unless you seed the random number generator to often).
N = 5 ;
r = zeros(10000,N) ;
for k=1:10,
r(:,k) = rand(10000,1) ;
end
c = corrcoef(r) % all very low, independence of N...

Community Treasure Hunt

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

Start Hunting!

Translated by