MATLAB: Setting min/max limits to the function random (not rand nor randn)

kernelrandomrandom number generatorStatistics and Machine Learning Toolbox

I am using the function RANDOM to generate random numbers with a specific Kernel PDF that I created using FITDIST. Is there a way to control the min/max of the generated random numbers?
pd1 = fitdist((data(:,1)),'Kernel');
Y1 = random(pd1,100000,1);

Best Answer

The easiest way to do this in your context is to restrict the actual PDF you're using to generate the random variable, rather than do a resampling of the random number. You can do this by calling the Support property:
pd = fitdist(x,'Kernel','Support',[100,250])
Where the bound of the support are in this example [100,250]. The random function will then not generate numbers outside this range.