public static void main(String[] args) {
List<Person>listP=new ArrayList<Person>()
listP.add(new Person("小李", "1", 200))
listP.add(new Person("小王", "2", 210))
listP.add(new Person("小赵", "3", 230))
listP.add(new Person("小孙", "4", 100))
listP.add(new Person("小钱", "5", 3))
listP.sort(new Comparator<Person>() {
@Override
public int compare(Person o1, Person o2) {
// TODO Auto-generated method stub
return (((Person)o1).count)*(Math.random()*10+1)>(((Person)o2).count)*(Math.random()*10+1)?-1:1
}
})
System.out.println(listP)
}
}
class Person {
String personName
String id
int count
public Person(String personName, String id, int count) {
super()
this.personName = personName
this.id = id
this.count = count
}
@Override
public String toString() {
return "Person [personName=" + personName + ", id=" + id + ", count=" + count + "]"
}
}
//本质还是随机数
public class Lottery {private int m = 1000//发放奖券的数量private int n = 2//奖品的数量public boolean getLottery(){boolean isLottery = false double d = (double)n/(double)m//中奖概率double r = Math.random()//0~1之间的随机数,包括0if(r<d){//如果随机数小于概率 那么中奖n--//奖品数量-1isLottery = true }m--//奖券数量-1return isLottery }}