int getRandomData(double r, double[] weights) {
		double sum;
		if (r <= weights[0]) {
			return 0;
		}
		sum = 0;
		for (int s = 1; s < weights.length; s++) {
			if (r > sum && r <= sum + weights[s]) {
				return s;
			}
			sum += weights[s];
		}
		return weights.length-1;
	}