public static int randomM(int k, int max) {
		List<Integer> set = new ArrayList<Integer>();
		set.add(1);
		set.add(2);
		
		while(true) {
			Collections.shuffle(set);
			int a;
			if (r.nextBoolean()) {
				a = set.get(0) + set.get(1);
			} else {
				a = set.get(0)*2;
			}
			if (set.size() == max)
				return max;
			if (a == k) {
				return set.size();
			}
			if (a < k && !set.contains(a)) {
				set.add(a);
			}
			int diff = k-a;
			if (set.contains(diff))
				return Math.min(max, set.size());
			if (diff%2==0 && set.contains(diff/2))
				return Math.min(max,set.size()+1);
		}
	}