當前位置:首頁 » 編程語言 » java概率隨機

java概率隨機

發布時間: 2023-07-06 00:23:09

A. 求一段JAVA的概率演算法

public class Zhuq {
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 + "]";
}

}
//本質還是隨機數

熱點內容
分鏡腳本怎麼寫 發布:2025-09-14 09:52:45 瀏覽:997
sql10 發布:2025-09-14 09:51:05 瀏覽:692
安卓手機如何調用外置攝像頭 發布:2025-09-14 09:38:58 瀏覽:852
分布式爬蟲python 發布:2025-09-14 09:35:11 瀏覽:102
搭建gta伺服器 發布:2025-09-14 09:29:38 瀏覽:930
騰訊雲php 發布:2025-09-14 09:28:40 瀏覽:434
visualstudio編譯器在哪個位置 發布:2025-09-14 09:26:29 瀏覽:746
電視設了兒童版密碼多少 發布:2025-09-14 09:21:46 瀏覽:372
復制另一個資料庫的表 發布:2025-09-14 09:10:55 瀏覽:206
spotify緩存 發布:2025-09-14 09:00:07 瀏覽:613