用java实现取1-100之间的99个不重复的随机数 然后输出没有被取出的数字

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 + " ");
        }
    }
}

 

上一篇:条件 题解(bitset优化floyd)


下一篇:2019 ICPC Asia Taipei-Hsinchu Regional Problem J Automatic Control Machine (DFS,bitset)