@Override
    public int generate() {
        final long seed = this.seedSupplier.get();
        Random outRandom = new Random(seed);
        final ArrayList<Vertex> outStubs = new ArrayList<>(expectedNumEdges);

        for (Vertex v : out) {
            processVertex(v, Collections.EMPTY_MAP);
            final int degree = this.outDistribution.nextValue(outRandom);
            IntStream.range(0, degree).forEach(i -> outStubs.add(v));
        }

        outRandom = new Random(seed);
        Collections.shuffle(outStubs, outRandom);

        outRandom = new Random(seed);
        final Random inRandom = new Random(this.seedSupplier.get());
        int addedEdges = 0;
        int position = 0;
        for (Vertex v : in) {
            processVertex(v, Collections.EMPTY_MAP);
            final int degree = this.inDistribution.nextConditionalValue(inRandom, this.outDistribution.nextValue(outRandom));
            for (int i = 0; i < degree; i++) {
                Vertex other = null;
                while (null == other) {
                    if (position >= outStubs.size()) return addedEdges; //No more edges to connect
                    other = outStubs.get(position);
                    position++;
                    if (!allowLoops && v.equals(other)) other = null;
                }
                //Connect edge
                addEdge(other, v);
                addedEdges++;
            }
        }
        return addedEdges;
    }
Generates a synthetic network for a given out- and (optionally) in-degree distribution.

@author Matthias Broecheler (me@matthiasb.com)
@author Stephen Mallette (http://stephen.genoprime.com)
gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/algorithm/generator/DistributionGenerator.java