The RAND function in MATLAB is not random in generating numbers that are small. The generation of very small values following runs of not-small values is particularly low. Here is an example that illustrates the problem:
rand('state',0);n = 5*10^7;delta = .05;runs = diff(find(rand(n,1)<delta))-1;y = histc(runs, 0:100) ./ length(runs);plot(0:100,(1-delta).^(0:100).*delta,'k--', 0:100,y,'b-');title('Distribution of run lengths')xlabel('Run Length'); ylabel('Relative Frequency');legend({'Expected (Geometric) Distribution' 'Actual Distribution'})
This code plots the number of random numbers that must be generated until another very small random number is generated. From the plot we can see that there is a noticeable decrease in runs of length 27
Best Answer