public static int chooseOptionRandomlyWithWeights(boolean areValuesNormalizedToOne,
			double... weights) {
		double[] normalized;

		if (!areValuesNormalizedToOne) {
			normalized = new double[weights.length];

			double total = 0;
			for (double value : weights) {
				total += value;
			}

			int counter = 0;
			for (double value : weights) {
				normalized[counter] = value / total;
				counter++;
			}
		} else {
			normalized = weights;
		}

		double randomValue = random.nextDouble();
		int index = 0;
		for (double weight : normalized) {
			if (randomValue < weight) {
				return index;
			} else {
				randomValue -= weight;
				index++;
			}
		}

		String log = "";
		for (double d : weights) {
			log += d + " / ";
		}
		displayError("chooseOptionRandomlyWithWeights:\n" + log);
		return -1;
	}