private String getRandomCommandByWeight(Map<String, Integer> commands, Integer max)
    {
        int randomMax = rnd.nextInt(max);

        int randomValue = rnd.nextInt(commands.size());

        if ((Integer)commands.values().toArray()[randomValue] >= randomMax)
        {
            return (String)commands.keySet().toArray()[randomValue];
        }
        else
        {
            return getRandomCommandByWeight(commands, max);
        }
    }