function out=draw_from_pdf(x,pdf)
% Output value that - if numbers go to infinity - approaches the pdf

n=length(pdf);
i=0; 

while i==0
    m=ceil(rand*n);
    prob=pdf(m)/max(pdf);    % that is a number betwen 0 and 1
    test=rand;
    if test < prob, 
        i=m;
    else
        i=0;
    end

end

out=x(i);