Loading...

          java .net

          從指定的數(shù)組中隨機(jī)取n個(gè)

          import java.util.*;

          public class Test
          {
          public static void main(String[] agrs)
          {
             int[] allIdList = new int[]{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
             int[] randomIdList = new Test().getRandomIdList(allIdList,10);
             for(int randomIdList_index = 0;randomIdList_index < randomIdList.length;randomIdList_index++){
              System.out.println(randomIdList[randomIdList_index]);
             }
          }


          /**
          *
          * @author liuzhaochun
          * @explain:從指定的數(shù)組中隨機(jī)取count個(gè),返回這個(gè)數(shù)組
          * @datetime:2008-5-9
          * @return
          * @return int [] 包含隨機(jī)取的count個(gè)值的數(shù)組
          */
          public int[] getRandomIdList(int[] allIdList,int count){
            
             int[] randomIdList = new int[count];
             int randomIdList_index = 0;
             for(int allIdList_index = allIdList.length - 1; randomIdList_index < count;allIdList_index--,randomIdList_index++){
              int temp_Index = (int)(Math.random() * allIdList_index);
              randomIdList[randomIdList_index] = allIdList[temp_Index];
              allIdList[temp_Index] = allIdList[allIdList_index];
             }
             return randomIdList;
          }



          }

          posted on 2008-08-26 22:06 閱讀(464) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           

          公告

          希望有一天

          我能用鼠標(biāo)雙擊我的錢(qián)包

          然后選中一張100元

          按住“ctrl+c”

          接著不停的“ctrl+v”

          嘻嘻~~~笑醒~~~



          導(dǎo)航

          <2008年8月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          統(tǒng)計(jì)

          常用鏈接

          留言簿(6)

          隨筆分類(lèi)(102)

          隨筆檔案(398)

          文章分類(lèi)

          文章檔案(10)

          有趣網(wǎng)絡(luò)

          搜索

          積分與排名

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 黎川县| 侯马市| 边坝县| 商水县| 喜德县| 华坪县| 彭水| 贺兰县| 南汇区| 双桥区| 宜宾市| 香河县| 商城县| 专栏| 景宁| 鄂伦春自治旗| 新蔡县| 义乌市| 读书| 大邑县| 都昌县| 普洱| 德江县| 峨眉山市| 宜黄县| 姜堰市| 长垣县| 靖宇县| 麻江县| 沙雅县| 明溪县| 新宾| 高密市| 凤庆县| 加查县| 深水埗区| 蛟河市| 手游| 安国市| 拜泉县| 古蔺县|