public static int sample(double[] probs, int T) {
		// roulette sampling
		
		double []pt = new double[T];
		//System.out.print(p[0]);
		pt[0] = probs[0];
		for (int i = 1; i < T; i++) {
			pt[i] = probs[i] + pt[i-1];
//			System.out.print(" " + pt[i]);
		}
//		System.out.println();

		// scaled sample because of unnormalized p[]
		double rouletter = (double) (Math.random() * pt[T - 1]);
		short sample = 0;
		for (sample = 0; sample < T; sample++) {
			if (pt[sample] > rouletter)
				break;
		}
//		System.out.println(rouletter + "\t" + sample);
		
		if(sample < 0 | sample >= T) {
			ComUtil.print(probs, "\t", "\n");
			System.out.println("Sampling error!");
			System.exit(0);
		}
		return sample;
	}