void addRandomSprings() {
        List<Mass> network = grammar.getGraph().getNetworkMasses();
        List<Mass> inputs = grammar.getGraph().getInputs();

        if (network.isEmpty()) {
            return;
        }

        int maxMassIndex = network.size() - 1;
        int maxChoiceIndex = maxMassIndex + inputs.size();

        int createdSprings = 0;
        int loopCount = 0;

        while (loopCount < MAXIMAL_RANDOM_LOOP_COUNT_LIMIT && createdSprings < grammar.getNumberOfRandomSprings()) {
            loopCount++;

            int sourceIndex = random.nextInt(maxChoiceIndex);
            int destinationIndex = random.nextInt(maxChoiceIndex);

            if (sourceIndex == destinationIndex) {
                continue;
            }

            Mass source;
            Mass destination;

            if (sourceIndex > maxMassIndex) {
                int inputIndex = sourceIndex - maxMassIndex;
                source = inputs.get(inputIndex);
            } else {
                source = network.get(sourceIndex);
            }

            if (destinationIndex > maxMassIndex) {
                int inputIndex = destinationIndex - maxMassIndex;
                destination = inputs.get(inputIndex);
            } else {
                destination = network.get(destinationIndex);
            }
            
            if (source.getType() == NETWORK && PROBABILITY_TO_RANDOMLY_CHOOSE_INPUT >= random.nextDouble()) {
                if (destination.getType() != INPUT) {
                    destination = inputs.get(random.nextInt(inputs.size()));
                }
            }
            
            if (source.getType() == INPUT && destination.getType() == INPUT) {
                continue;
            }

            if (grammar.getGraph().hasSpringBetweenMasses(source, destination)) {
                continue;
            }

            grammar.getGraph().addSpring(source, destination);

            createdSprings++;
        }
    }