有 int count1、int count2,里面分别存放了一些id号,怎样在这些id号范围内,随机出100个不重复的随机数。

解决方案 »

  1.   

    LZ的问题不是很清楚啊,“int count1、int count2,里面分别存放了一些id号”能说的明白点么?
      

  2.   

    这是个考试系统分两种不同类型的题,我根据这些不同类型的题的标识,把他们的id号查出来,然后根据这些id号,取出试题的内容。所以要根据这些id号,随机出100道题。不知我说明白了没有?
      

  3.   

    不是数组,int count1=rs.getInt("id")
      

  4.   

    count2-count1  得到随机的范围系数 a
    a * Math.random() 取整 再加上count1  得到一个随机题目的ID  重复100次
      

  5.   

    count2-count1  得到随机的范围系数 a
    id = count1
    id = id + Math.round(a / 100 * Math.random()) 重复98次 得到有顺序的ID号
      

  6.   

    //晕,你100个ID不能放一个变量里吧?这样吧,我假设你把这些id放在两个数组里:
    int[] counts1;
    int[] counts2;
    Random  r  = new Random();  
    int  i  =  0;  
    int  c; 
    int[] count_result=new int[100];
    while(i<100){  
    int flag=r.nextInt(2);
    int[] tempCount;
    if(flag==1)tempCount=counts1;
    else tempCount=counts2;
    int n=tempCount.length;
    c=r.nextInt(n);
    if(tempCount[c]!=-1){  
    count_result[i]=tempCount[c];
    if(flag==1)counts1[c]=-1;
    else counts2[c]=-1;   
    i++;  
    }  
    }
    for(int j=0;j<100;j++){
    out.println(count_result[j]);
    }
      

  7.   

    不能减吧,count1和count2,里面不是一个数,而是这样的count1=7382921041131221321411501591681771861952042132222312,都是id号。按照那样的方法取出的都是同一道题。
      

  8.   

    int[] a = new int[100];
    for(int i = 0 ; i < 100 ; i++){ a[i] = i;}
    int n = a.length;
    for(int i = 99 ; i >= 0 ; i--)
    {
         int temp = (int)(Math.random()*n--);
         System.out.println(a[temp]);
         a[temp] = a[i]; //把该次随机到的数的位置放最后一个数
    }