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)論排行榜

          主站蜘蛛池模板: 屏东县| 华亭县| 蓝田县| 泌阳县| 耒阳市| 洞头县| 吉木萨尔县| 隆尧县| 昭平县| 康马县| 贡山| 铜陵市| 岳阳县| 绵竹市| 保山市| 前郭尔| 淳化县| 本溪| 顺平县| 西和县| 施甸县| 乳山市| 辰溪县| 霍邱县| 清苑县| 夹江县| 谷城县| 沽源县| 洛川县| 五大连池市| 安图县| 修文县| 原平市| 天柱县| 邢台县| 永修县| 绵阳市| 新晃| 临汾市| 泰州市| 玉环县|