function [ i ] = gera_inteiro( p, N )

if nargin<2
    N = 1;
end
C = cumsum( p );
C = C / C(end);
i = zeros(N,1);
for n = 1:N
    r = rand;
    for j=1:length(p)
        if r<=C(j)
            i(n) = j;
            break
        end
    end
end