MATLAB: Create Non-uniform distribution

random number generatorstatistics

Hello!
I want to create non -uniform distribution using rand. for example, let X be random integer number with :
X=
0 w.p 1/3
1 w.p 1/2
2 w.p 1/6
meaning, with p =1/3 x is equal to 0, with p=1/2 x is equal to 1, and with p=1/6 x is equal to 2.
how can I set a series of Xi random numbers using rand (1,N)?
Thanks In Advance.

Best Answer

This should do it:
x = rand;
x = (x>1/3)+(x>5/6);