Draw random numbers from pre-specified probability mass function in Matlab

Using the Statistics Toolbox The randsample function can do that directly: result = randsample(supp_epsilon, n, true, pr_mass_epsilon); Without using toolboxes Manual approach: Generate n samples of a uniform random variable in the interval (0,1). Compare each sample with the distribution function (cumulative sum of mass function). See in which interval of the distribution function each … Read more