public static <E> E sample(Counter<E> counter) {
	  double total = counter.totalCount();
	  double rand = random.nextDouble();
	  double sum = 0.0;
	  if (total <= 0.0) {
		  throw new RuntimeException("Non-positive counter total: " + total);
	  }
	  for (E key: counter.keySet()) {
		  double count = counter.getCount(key);
		  if (count < 0.0) {
			  throw new RuntimeException("Negative count in counter: " + key + " => " + count);
		  }
		  double prob = count / total;		  
		  sum += prob;
		  if (rand < sum) {
			  return key;
		  }
	  }
	  throw new RuntimeException("Shouldn't Reach Here");
  }