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 閱讀(463) 評(píng)論(0)  編輯  收藏


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


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

          公告

          希望有一天

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

          然后選中一張100元

          按住“ctrl+c”

          接著不停的“ctrl+v”

          嘻嘻~~~笑醒~~~



          導(dǎo)航

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

          統(tǒng)計(jì)

          常用鏈接

          留言簿(6)

          隨筆分類(102)

          隨筆檔案(398)

          文章分類

          文章檔案(10)

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

          搜索

          積分與排名

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 铜梁县| 怀仁县| 尤溪县| 明星| 开封县| 石景山区| 江永县| 宜章县| 烟台市| 新蔡县| 九龙城区| 晋州市| 米脂县| 延吉市| 东海县| 辽中县| 澄迈县| 如皋市| 清水县| 华阴市| 揭阳市| 岳池县| 扶余县| 宜都市| 寻乌县| 漠河县| 黄大仙区| 普定县| 晋城| 德州市| 南江县| 子洲县| 奇台县| 姚安县| 略阳县| 江达县| 札达县| 贵州省| 利津县| 彭泽县| 丰台区|