public class RondamIntGenerator
 {
    public RondamIntGenerator(int l,int h)
  {
  high=h;
  low=l;
 
        }
  public int draw()
  {
  int r=low+(int)((high -low +1)*nextRandom());
  if(r>high) r=high;
  return r;

  }
        public static void main(String args[])
        {
        RondamIntGenerator r1=new RondamIntGenerator(1,10);
        RondamIntGenerator r2=new RondamIntGenerator(0,1);
int i;
for(i=0;i<=100;i++)

System.out.println(r1.draw()+" "+r2.draw());

        } 
        
        private static double nextRandom()
        {
        int pos=(int)(java.lang.Math.random()*BUFFER_SIZE);
        if (pos==BUFFER_SIZE) pos=BUFFER_SIZE-1;
        double r=buffer[pos];
        buffer[pos]=java.lang.Math.random();
        return r;
        
        }
         
        private static final int BUFFER_SIZE=101;
        private static double[] buffer=new double[BUFFER_SIZE];
        static
        {
        int i;
        for(i=0;i<BUFFER_SIZE;i++)
        buffer[i]=java.lang.Math.random();
        
        }
        private int low;
        private int high;
         
 }

解决方案 »

  1.   

    public class RondamIntGenerator
     {
    public static final int BUFFER_SIZE=101;
    public static double[] buffer=new double[BUFFER_SIZE];
    static
    {
    int i;
    for(i=0;i<BUFFER_SIZE;i++)
    buffer[i]=java.lang.Math.random();}
    private int low;
            private int high;
             public RondamIntGenerator(int l,int h)
             {
                     high=h;
                     low=l;        }
             public int draw()
             {
             int r=low+(int)((high -low +1)*nextRandom());
             if(r>high) r=high;
             return r;         }
            public static void main(String args[])
            {
            RondamIntGenerator r1=new RondamIntGenerator(1,10);
            RondamIntGenerator r2=new RondamIntGenerator(0,1);
            int i;
            for(i=0;i<=100;i++)        System.out.println(r1.draw()+" "+r2.draw());        }        private static double nextRandom()
            {
            int pos=(int)(java.lang.Math.random()*BUFFER_SIZE);
            if (pos==BUFFER_SIZE) pos=BUFFER_SIZE-1;
            double r=buffer[pos];
            buffer[pos]=java.lang.Math.random();
            return r;        }
     }
      

  2.   

    //this is the file which can be compiled, but still not know whether can run.i will try it laterpublic class RondamIntGenerator
    {
    public RondamIntGenerator(int l,int h)
    {
    high=h;
    low=l;

    }
    public int draw()
    {
    int r=low+(int)((high -low +1)*nextRandom());
    if(r>high) r=high;
    return r;

    }
    public static void main(String args[])
    {
    RondamIntGenerator r1=new RondamIntGenerator(1,10);
    RondamIntGenerator r2=new RondamIntGenerator(0,1);
    int i;
    for(i=0;i<=100;i++)

    System.out.println(r1.draw()+" "+r2.draw());



    private static double nextRandom()
    {
    int pos=(int)(java.lang.Math.random()*BUFFER_SIZE);
    if (pos==BUFFER_SIZE) pos=BUFFER_SIZE-1;
    double r=buffer[pos];
    buffer[pos]=java.lang.Math.random();
    return r;

    }

    private static final int BUFFER_SIZE=101;
    private static double[] buffer=new double[BUFFER_SIZE];
    static
    {
    int i;
    for(i=0;i<BUFFER_SIZE;i++)
    buffer[i]=java.lang.Math.random();

    }
    private int low;
    private int high;


      

  3.   

    public class RondamIntGenerator  {    private static final int BUFFER_SIZE=101;
        private static double[]buffer=new double[BUFFER_SIZE];
        private int low;
        private int high; public RondamIntGenerator(int l,int h) {
      high=h;
      low=l;
    }
      public int draw() {
    int r=low+(int)((high -low +1)*nextRandom());
    if(r>high) r=high;
    return r;
      }
        
    public static void main(String args[]) {
            RondamIntGenerator r1=new RondamIntGenerator(1,10);
            RondamIntGenerator r2=new RondamIntGenerator(0,1);
    int i;
    for(i=0;i<=100;i++)
    System.out.println(r1.draw()+" "+r2.draw());
            } 
            
            private static double nextRandom() {
    int pos=(int)(java.lang.Math.random()*BUFFER_SIZE);
    if (pos==BUFFER_SIZE) pos=BUFFER_SIZE-1;
    double r=buffer[pos];
    buffer[pos]=java.lang.Math.random();
    return r;
            }
             
            static {
    int i;
    for(i=0;i<BUFFER_SIZE;i++)
    buffer[i]=java.lang.Math.random();
            }
     } 调好了,主要是你写错的太多,把我改的跟你的比比,要注意阿,不要写错了。
      

  4.   

    //the class can be run.see the following result, is it the one u want?
    Starting application C:\WINNT\Profiles\lizhaosong\Desktop\RondamIntGenerator.class
    5 0
    3 1
    2 0
    3 0
    7 0
    8 0
    8 1
    10 0
    8 0
    10 0
    7 1
    10 0
    4 0
    6 0
    1 1
    8 1
    9 1
    8 1
    5 1
    4 1
    5 0
    1 0
    3 0
    4 1
    10 0
    7 0
    8 0
    9 1
    1 0
    4 1
    9 0
    4 1
    10 1
    5 0
    7 1
    2 1
    9 1
    8 0
    4 0
    5 1
    10 0
    7 1
    5 0
    10 0
    10 1
    9 1
    3 1
    7 0
    8 1
    7 0
    5 1
    10 1
    5 0
    7 0
    10 1
    7 0
    10 1
    5 1
    7 1
    6 1
    1 0
    1 0
    7 1
    8 1
    9 1
    9 0
    4 1
    6 1
    6 0
    5 1
    10 0
    7 0
    6 0
    2 1
    7 1
    4 0
    8 0
    2 1
    1 1
    2 0
    4 0
    7 0
    8 1
    3 0
    4 1
    4 1
    9 0
    4 1
    3 0
    10 1
    1 0
    10 1
    Interactive Session Ended
    9 0
    9 1
    10 1
    4 0
    4 1
    2 0
    5 1
    3 1
    9 1