package com.liushuaishuai; import java.util.HashSet; import java.util.Random; import java.util.Set; import java.util.TreeSet; public class RandomDemo01 { public static void main(String[] args) { Set<Integer> ts = new HashSet<Integer>(); Random rd = new Random(); while (ts.size() < 10) { int x = rd.nextInt(20) + 1; ts.add(x); } for (int s : ts) { System.out.println(s); } } }