function i=get_index_from_pdf(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