- import java.util.*;
- public class RandomNumberDemo {
- public static void main(String[] args) {
- System.out.println(getRandom());
- }
- public static List<Integer> getRandom() {
- Random rd = new Random();
- ArrayList<Integer> al = new ArrayList<Integer>();
- int i = 0;
- while(i != 10)
- {
- int r = rd.nextInt(20);
- if(!al.contains(rd)){
- al.add(r);
- i++;
- }
- }
- return al;
- }
- }
复制代码
|
|