On Wednesday, May 21, 2014 5:35:12 AM UTC+12, Anindya G wrote: > Hello, > > > > I have been trying to generate random numbers for a "weighted uniform" probability distribution p(x) where > > p(x) = p0 for 0 <= x < a1, > > = p1 for a1 <= x <= a2, > > = ... > > = pn for an < x <= 1. > > Also, p1, p2, ... pn are chosen such that the integral(p(x)) = 1. > > So, in general, p(x) will have n probability weights for n intervals. The random number generator should take a vector of weights, and intervals to generate k (say) random numbers. > > > > I am wondering how can I use rand function to generate k random numbers for such a pdf. I understand that I can use rand function to generate random numbers for any pdf as explained in this post: http://www.mathworks.com/matlabcentral/newsreader/view_thread/173000 > > > > But I am not clear how can I specify the integral expression in MATLAB for the weighted uniform distribution? Any help/hints will be greatly appreciated. > > > > Anindya.