Then populate a matrix with all possible numbers covered by the bins which the approximation can choose:

sizes = transpose(1:binsize*nbins);

To use the bin counts as weights for selection i.e. bincount (1-5) = 2, thus the weight for choosing 1,2,3,4 or 5 = 2 whilst (16-20) = 0 so 16,17,18, 19 or 20 can never be chosen, I simply take the bincounts and replicate them across the bin size:

w = repelem(bincounts,binsize);

To then perform weighted number selection, I use:

[~,R] = histc(rand(1,1),cumsum([0;w(:)./sum(w)]));
R = sizes(R);

For some reason this approach is unable to approximate the data. It was my understanding that was sufficient sampling depth, the binned version of R would be identical to the binned version of eventl however there is significant variation and often data found in bins whose weights were 0.

Could anybody suggest a better method to do this or point out the error?