public static <VT> int[] generateRandomHopsOut(Random r, ChiVertex<VT, Float> vertex, int n) {
        int l = vertex.numOutEdges();
        float[] cumDist = new float[l];
        float prefix = 0.0f;
        for(int i=0; i < l; i++) {
            float x =  vertex.getOutEdgeValue(i);
            cumDist[i] = prefix + x;
            prefix += x;
        }

        int[] hops = new int[n];
        for(int i=0; i < n; i++) {
            float x = prefix * r.nextFloat();
            if (l > 32)  {
                int h = Arrays.binarySearch(cumDist, x);
                if (h < 0) h = -(h + 1);
                hops[i] = h;
            } else {
                // linear scan
                for(int j=0; j < l; j++) {
                    if (cumDist[j] > x) {
                        hops[i] = j;
                        break;
                    }
                }
            }
        }
        return hops;
    }