package choujiang;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
public class cj {
ArrayList
static ArrayList
public ArrayList
if (list==null){
list=new ArrayList
for(int i=1;i<=200;i++)
list.add(i);
}
Collections.shuffle(list);
return list;
}
public void display(){
Random r=new Random();
int a=r.nextInt(200);
System.out.println("一等奖"+list.get(a)+"号");
list.remove(a);
for(int j=1;j<=10;j++){
a=r.nextInt(200);
System.out.println("二等奖"+list.get(a)+"号");
list.remove(a);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
cj a=new cj();
a.addPerson();
a.display();
// b= a.addPerson();
// System.out.println(b);
}
}
该程序主要是对随机排列功能的实现,体现抽奖的随机性,用random和collection类的shuffle方法对list重新排列 ,将随机性加大