private S mapMap(final Map map) {
        if (map.size() <= this.amountToSample)
            return (S) map;

        final List<Map.Entry> original = new ArrayList<>(map.entrySet());
        final Map target = new LinkedHashMap<>(this.amountToSample);
        while (target.size() < this.amountToSample) {
            final Map.Entry entry = original.remove(random.nextInt(original.size()));
            target.put(entry.getKey(), entry.getValue());
        }
        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