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.
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) ;
r(:,k) = rand(10000,1) ;
c = corrcoef(r) % all very low, independence of N...