public class RadomTest {
public static void main(String []str){
double d = Math.random()*67;
while(d<33 || d>66){
d = Math.random()*67;
}
System.out.println("number"+d);
}
}
不知道这样行不行.可能得到的那个字还要format 一下.

解决方案 »

  1.   

    public class RandomInt
    {
        public static void main(String[] args)
        { int a=33;
    int b=0;
         double c=33.0*Math.random();
         b=(int)(a+c);
         System.out.println(b);
        }
    }
      

  2.   

    public class RandomInt
    {
        public static void main(String[] args)
        {
    int a=0;
         double b=33.0*Math.random();
         int c=0;
         a=(int)(33+b);
         while(b!=38&b!=44)
         {
         c=a;
         System.out.println(c);
         }
        }
    }
    c就是你要的数
      

  3.   

    to allenbailin
      你是在33& 66之间取的时候不能有重复的数出现.
    是不是只取两个,那只要加一个判断条件就OK了,如果是取33与66之间的33个不重复的数,那这样的话,你可能要用到hashmap实现了.
      

  4.   

    刚才那个有问题
    public class RandomInt
    {
        public static void main(String[] args)
        {
    int a=0;
         double b=33.0*Math.random();
         int c=0;
         while(b!=38&b!=44)
         {
         b=33.0*Math.random();
         a=(int)(33+b);
         c=a;
         System.out.println(c);
         break;
         }
        }
    }
      

  5.   

    int i = (int) (33 + Math.random() * 33);
      

  6.   

    生成30个33到66间随机数的例子:public class RandomNumber
    {
      public static void main(String[] args)
      {
        int i;
        for (int j = 0; j < 30; ++j)
        {
          i = (int) (33 + Math.random() * 33);
          System.out.println(i);
        }
      }
    }
      

  7.   

    严格说来,上面的方法得到的随机数是33到65,得不到66,应该改动为
    i = (int) (33 + Math.random() * 34);其实可以做一个通用的得到某区间随机数的方法,以方便使用,比如: static int randomNew(int begin,int end)
      {
        return (int) (begin + Math.random() * (end-begin+1));
      }
    以下是得到从66到99之间的随机数的例子
    public class RandomNumber
    {
      static int randomNew(int begin,int end)
      {
        return (int) (begin + Math.random() * (end-begin+1));
      }
      public static void main(String[] args)
      {
        int i;
        for (int j = 0; j < 30; ++j)
        {
          i = randomNew(99,66); //效果等同于 i=randomNew(66,99);
          System.out.println(i);
        }
      }
    }
      

  8.   

    好吧,现在得到30个不重复出现的33到66之间的随机数,并且不包含楼主指出的38和44:public class RandomNumber
    {
      public static void main(String[] args)
      {
        int i;
        int[] array = new int[32]; //33到66但不包括38和44一共有32种可能
        for (int j = 0; j < 32; j++)
        {
          array[j] = 33 + j; //准备备选数据集
        }
        array[5] = 65; //原来为需要排除的38,换为缺少的65
        array[11] = 66; //原来为需要排除的44,换为缺少的66    for (int j = 0; j < 30; ++j)
        {
          i = (int) (Math.random() * (32 - j)); //得到随机下标
          System.out.println(array[i]); //得到随机数
          for (int k = i; k < 32 - 1; k++)
          {
            array[k] = array[k + 1]; //调整备选数据(为了不取重复随机数)
          }
        }
      }
    }
      

  9.   

    public static double random():Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0. Returned values are chosen pseudorandomly with (approximately) uniform distribution from that range. 汗……Math.random()取的值在0.0——1.0之间,我居然今天才知道,5555~~~~
      

  10.   

    因为random()得到的只是半闭区间(左闭右开),如果你要得到33和66,也就是两边都是闭区间,则应该做额外的判断;
    int value = 0;
    while (true) {
        value = (int)(Math.random() * 67);
        if (value>32 && value<67) {
            break;
        }
    }
      

  11.   

    jsp中用jfreechart包做linechart数据点显示问题
    http://expert.csdn.net/Expert/topic/2953/2953628.xml?temp=.726742