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 + " "); } } }
原文地址:https://www.cnblogs.com/VisionY/p/11290316.html
时间: 2024-10-11 16:18:02