int select_roulette(double probs[], double sum)
    {
        double acum = 0;
        int res = 0;
        double tope = rnd.nextDouble()*sum;
        while(res<probs.length && acum < tope) {
            acum += probs[res++];
        }
        if(res==probs.length)
            res--;
        return res;
    }