public BinarySearchDistribution(double[] weights) {
		//compute sum
		try {
			double sum = 0.0;
			for (int i = 0; i < weights.length; i++) {

				if (weights[i] < 0) {
					throw new IllegalArgumentException("All Weights Must be non-negative :: " + weights[i]);
				}

				sum += weights[i];
			}

			//build cummulativeMassFunction array
			this.cummMassFun = new double[weights.length];
			cummMassFun[0] = weights[0];
			for (int i = 1; i < weights.length; i++) {
				cummMassFun[i] = (cummMassFun[i - 1] + weights[i]);
			}
			for (int i = 0; i < cummMassFun.length; i++) {
				cummMassFun[i] /= sum;
			}

			//test cummulativeMassFunction
			for (int i = 1; i < cummMassFun.length; i++) {
				if (cummMassFun[i] < cummMassFun[i - 1]) {
					throw new IllegalStateException();
				}
			}
			if (cummMassFun[cummMassFun.length - 1] != 1) {
				throw new IllegalStateException("Not equal to 1");
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}