java 从1到1亿随机 找出未出现的数字

public class Test {
	public static void main(String args[]) {
		BitSet used = new BitSet();
		Random rand = new Random(47);
		for (int i = 1; i < 100000001; i++) {
			used.set(rand.nextInt(100000000) + 1); // set bit for char
		}
		List list = new ArrayList();
		for (int i = 1; i < 100000001; i++) {
			if (!used.get(i))
				list.add(i);

		}
		System.out.println(list.size());
	}
}

你可能感兴趣的:(java)