欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

使用Java怎么獲取指定個(gè)數(shù)的不同隨機(jī)數(shù)

使用Java怎么獲取指定個(gè)數(shù)的不同隨機(jī)數(shù)?相信很多沒有經(jīng)驗(yàn)的人對(duì)此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個(gè)問題。

在網(wǎng)站設(shè)計(jì)、網(wǎng)站制作中從網(wǎng)站色彩、結(jié)構(gòu)布局、欄目設(shè)置、關(guān)鍵詞群組等細(xì)微處著手,突出企業(yè)的產(chǎn)品/服務(wù)/品牌,幫助企業(yè)鎖定精準(zhǔn)用戶,提高在線咨詢和轉(zhuǎn)化,使成都網(wǎng)站營(yíng)銷成為有效果、有回報(bào)的無錫營(yíng)銷推廣。成都創(chuàng)新互聯(lián)專業(yè)成都網(wǎng)站建設(shè)十余年了,客戶滿意度97.8%,歡迎成都創(chuàng)新互聯(lián)客戶聯(lián)系。

1、隨機(jī)拆分一個(gè)整數(shù)

public static List<Integer> randomList(int n){
    Random rand = new Random();
    List<Integer> list = new ArrayList<>();
    int i = 0;
    while (i < n) {
      int num = rand.nextInt(n);
      if (!list.contains(num)) {
        list.add(num);
        i++;
      }
    }
    return list;
 }

2、從已知列表中隨機(jī)選取不同對(duì)象 

public static List<Integer> randomList(int n,int size) {
    Random rand = new Random();
    List<Integer> list = new ArrayList<>();
    int i = 1;
    while (i <= n) {
      int num = rand.nextInt(size-1) + 1;
      if (!list.contains(num)) {
        list.add(num);
        i++;
      }
    }
    return list;
 }

3、把一個(gè)整數(shù)拆分成不等的幾份

public static List<Integer> randomList(int n, int m){
 Random rand = new Random();
 List<Integer> list = new ArrayList<>();
 int temp = m;
 for(int i = 0, j; i < n-1; i++){
 j = rand.nextInt(temp-1) + 1;
 temp -= j;
 list.add(j);
 if (temp == 1){
  break;
 }
 }
 list.add(temp);
 return list;
}

看完上述內(nèi)容,你們掌握使用Java怎么獲取指定個(gè)數(shù)的不同隨機(jī)數(shù)的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!

文章標(biāo)題:使用Java怎么獲取指定個(gè)數(shù)的不同隨機(jī)數(shù)
瀏覽路徑:http://chinadenli.net/article16/jhhhgg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊(cè)、網(wǎng)站策劃網(wǎng)頁(yè)設(shè)計(jì)公司、網(wǎng)站排名網(wǎng)站設(shè)計(jì)公司、自適應(yīng)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

綿陽(yáng)服務(wù)器托管