- import java.util.HashSet;
- import java.util.Random;
- import java.util.Set;
- @SuppressWarnings("all")
- /*
- * 生成十不重复的随机数
- *
- * */
- public class RandomText {
- public static void main(String[] args) {
- int last=0;
- Random ran=new Random();
- Set<Integer> set=new HashSet<Integer>();
- int index=0;
- while(set.size()<10){
- set.add(ran.nextInt(20));
- }
- for (Integer s : set) {
- System.out.println(s);
- }
- }
- }
复制代码 |
|