package com.sky;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
public class Test02 {
public static void main(String[] args){
ArrayList<Integer> list = new ArrayList<>();
Collections.addAll(list,1,1,1,1,1,1,1);
Collections.addAll(list,2,2,2);
Collections.shuffle(list);
Random r = new Random();
int index = r.nextInt(list.size());
int number = list.get(index);
}
}
package com.sky;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
public class Test01 {
public static void main(String[] args){
ArrayList<String> list = new ArrayList<>();
Collections.addAll(list,"张三","李四","王五","赵六","田七","范闲","杜子腾","刘大");
Random r = new Random();
int index = r.nextInt(list.size());
String name = list.get(index);
System.out.println(name);
}
}