package cn.kgc.springtest2.demo1.dao;

import java.util.BitSet;

/**
 * @author
 * @create 2019-08-02 17:46
 **/
public class sss {
    public static void main(String[] args) {
        BitSet bs = new BitSet(100);
        for (int count = 0; count < 99;) {
            int random = (int) (Math.random() * 100);
            if (!bs.get(random)) {
                bs.set(random);
                count++;
            }
        }
        //输出没有被取出的数字
        System.out.println(bs.nextClearBit(0));
        System.out.println();
        for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) {
            //输出不重复的随机数
            System.out.print(i + " ");
        }
    }
}

 

posted on 2019-08-02 17:58  森花  阅读(625)  评论(0编辑  收藏  举报