function k=randint(p)
  n=length(p);
  for i=1:n
    sump(i)=sum(p(1:i));
  endfor
  r=rand;
# sump
 
  for i=1:n
    if (r< sump(i))
      k=i;
      return;
    else
    endif
  endfor

endfunction