private S mapCollection(final Collection collection) {
        if (collection.size() <= this.amountToSample)
            return (S) collection;

        final List<S> original = new ArrayList<>(collection);
        final List<S> target = new ArrayList<>();
        while (target.size() < this.amountToSample) {
            target.add(original.remove(random.nextInt(original.size())));
        }
        return (S) target;
    }
@author Daniel Kuppitz (http://gremlin.guru)
@author Marko A. Rodriguez (http://markorodriguez.com)
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SampleLocalStep.java