Package com.nr.ran

Examples of com.nr.ran.Ran


   

    // Test Gray
    System.out.println("Testing Gray");

    Ran myran = new Ran(17);
    Gray g=new Gray();
    for (i=0;i<N;i++) {
      j=myran.int32();
      k=g.gray(j);
      m=g.gray(j+1);
      p = m ^ k;    // p should be a power of 2 (i.e. 1 bit set)
//      System.out.printf(k << " %f\n", m << " %f\n", p);
      localflag = localflag || (p & (p-1)) != 0// test for a power of 2
    }
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Gray: Gray code gave a value that differed from argument in more than 1 bit position");
     
    }

    // Test invgray
    System.out.println("Testing invgray");
    for (i=0;i<N;i++) {
      j=myran.int32();
      k=g.gray(j);
      m=g.invgray(k);
//      System.out.printf(j << " %f\n", m);
      localflag = localflag || (m != j);
    }
View Full Code Here


    if (localflag) {
      fail("*** Primpolytest: A known primitive polynomial was not identified as such.");
     
    }

    Ran myran = new Ran(17);
    mask = ((((long)1 << 32) - 1) >> 1);
    for (i=0;i<N;i++) {
      nflag=ptest.test((long)(myran.int32()) & mask);
      localflag = localflag || nflag!=0;
    }
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Primpolytest: A randomly generated 31 bit integer tested positive (unlikely).");
View Full Code Here

   

    // Test Sphcirc
    System.out.println("Testing Sphcirc");

    Ran myran=new Ran(17);

    // Test method operator== in 2D
    Sphcirc[] circ=new Sphcirc[N];
   
    for (i=0;i<N;i++) {
      circ[i] = new Sphcirc(2);
      circ[i].center.x[0]=myran.doub();
      circ[i].center.x[1]=myran.doub();
      circ[i].radius=myran.doub();
    }
    // Make every fifth circle identical
    for (i=5;i<N;i+=5)
      circ[i]=circ[0];
    Sphcirc ctest=new Sphcirc(circ[0].center,circ[0].radius);
    for (i=0;i<N;i++) {
      j=myran.int32p() % N;
      test = (circ[j].equals(ctest));
      localflag = (test != (j % 5 == 0));
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** Sphcirc,operator==(),2D: Incorrect signal of whether two circles are identical");
       
      }
    }

    // Test method isinbox() in 2D
    Point lo=new Point(2),hi=new Point(2);
    double boxsize=0.8,sphsize=0.25;
    for (i=0;i<N;i++) {
      p21.x[0]=myran.doub();
      p21.x[1]=myran.doub();

      lo.x[0]=p21.x[0]-boxsize;
      hi.x[0]=p21.x[0]+boxsize;
      lo.x[1]=p21.x[1]-boxsize;
      hi.x[1]=p21.x[1]+boxsize;
      Box box1=new Box(lo,hi);

      p22.x[0]=myran.doub();
      p22.x[1]=myran.doub();
      Sphcirc sph1=new Sphcirc(p22,sphsize);

//      System.out.printf(sph1.isinbox(box1));
      test=(sph1.isinbox(box1) != 0);

      localflag = (test != (
        (abs(p21.x[0]-p22.x[0]) <= (boxsize-sphsize))
        && (abs(p21.x[1]-p22.x[1]) <= (boxsize-sphsize))));
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** Sphcirc,isinbox(),2D: Incorrect signal of whether the circle is inside the box");
       
      }
    }

    // Test method contains() in 2D
    for (i=0;i<N;i++) {
      p21.x[0]=myran.doub();
      p21.x[1]=myran.doub();
      radius1=myran.doub();
      Sphcirc sph1=new Sphcirc(p21,radius1);

      p22.x[0]=myran.doub();
      p22.x[1]=myran.doub();

//      System.out.printf(sph1.contains(p22));
      test=(sph1.contains(p22) != 0);
      localflag = (test != (dist(p21,p22) < radius1));
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** Sphcirc,contains(),2D: Incorrect signal of whether point is in circle");
       
      }
    }

    // Test method collides() in 2D
    for (i=0;i<N;i++) {
      p21.x[0]=myran.doub();
      p21.x[1]=myran.doub();
      radius1=0.5*myran.doub();
      Sphcirc sph1=new Sphcirc(p21,radius1);

      p22.x[0]=myran.doub();
      p22.x[1]=myran.doub();
      radius2=0.5*myran.doub();
      Sphcirc sph2=new Sphcirc(p22,radius2);

//      System.out.printf(sph1.collides(sph2));
      test=(sph1.collides(sph2) != 0);
      localflag = (test != (dist(p21,p22) < (radius1+radius2)));
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** Sphcirc,collides(),2D: Incorrect identification of colliding circles");
       
      }
    }

    // Test method operator== in 3D
    Sphcirc[] circ3=new Sphcirc[N];
    for (i=0;i<N;i++) {
      circ3[i] = new Sphcirc(3);
      circ3[i].center.x[0]=myran.doub();
      circ3[i].center.x[1]=myran.doub();
      circ3[i].center.x[2]=myran.doub();
      circ3[i].radius=myran.doub();
    }
    // Make every fifth circle identical
    for (i=5;i<N;i+=5)
      circ3[i]=circ3[0];
    Sphcirc ctest3=new Sphcirc(circ3[0].center,circ3[0].radius);
    for (i=0;i<N;i++) {
      j=myran.int32p() % N;
      test = (circ3[j].equals(ctest3));
      localflag = (test != (j % 5 == 0));
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** Sphcirc,operator==(),3D: Incorrect signal of whether two circles are identical");
       
      }
    }

    // Test method isinbox() in 3D
    Point lo3=new Point(3),hi3=new Point(3);
    boxsize=0.8;sphsize=0.25;
    for (i=0;i<N;i++) {
      p31.x[0]=myran.doub();
      p31.x[1]=myran.doub();
      p31.x[2]=myran.doub();

      lo3.x[0]=p31.x[0]-boxsize;
      hi3.x[0]=p31.x[0]+boxsize;
      lo3.x[1]=p31.x[1]-boxsize;
      hi3.x[1]=p31.x[1]+boxsize;
      lo3.x[2]=p31.x[2]-boxsize;
      hi3.x[2]=p31.x[2]+boxsize;
      Box box1=new Box(lo3,hi3);

      p32.x[0]=myran.doub();
      p32.x[1]=myran.doub();
      p32.x[2]=myran.doub();
      Sphcirc sph1=new Sphcirc(p32,sphsize);

//      System.out.printf(sph1.isinbox(box1));
      test=(sph1.isinbox(box1) != 0);

      localflag = (test != (
        (abs(p31.x[0]-p32.x[0]) <= (boxsize-sphsize))
        && (abs(p31.x[1]-p32.x[1]) <= (boxsize-sphsize))
        && (abs(p31.x[2]-p32.x[2]) <= (boxsize-sphsize)))
      );
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** Sphcirc,isinbox(),3D: Incorrect signal of whether the circle is inside the box");
       
      }
    }

    // Test method contains() in 3D
    for (i=0;i<N;i++) {
      p31.x[0]=myran.doub();
      p31.x[1]=myran.doub();
      p31.x[2]=myran.doub();
      radius1=myran.doub();
      Sphcirc sph1=new Sphcirc(p31,radius1);

      p32.x[0]=myran.doub();
      p32.x[1]=myran.doub();
      p32.x[2]=myran.doub();

//      System.out.printf(sph2.contains(p32));
      test=(sph1.contains(p32) != 0);
      localflag = (test != (dist(p31,p32) < radius1));
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** Sphcirc,contains(),3D: Incorrect signal of whether point is in circle");
       
      }
    }

    // Test method collides() in 3D
    for (i=0;i<N;i++) {
      p31.x[0]=myran.doub();
      p31.x[1]=myran.doub();
      p31.x[2]=myran.doub();
      radius1=0.5*myran.doub();
      Sphcirc sph1=new Sphcirc(p31,radius1);

      p32.x[0]=myran.doub();
      p32.x[1]=myran.doub();
      p32.x[2]=myran.doub();
      radius2=0.5*myran.doub();
      Sphcirc sph2=new Sphcirc(p32,radius2);

//      System.out.printf(sph3.collides(sph4));
      test=(sph1.collides(sph2) != 0);
      localflag = (test != (dist(p31,p32) < (radius1+radius2)));
View Full Code Here

    System.out.println("Testing Huffcode");

    // Create a random message in vowellish with character frequencies
    // as given in the book
    // a= 0.12  e=0.42  i=0.09  o=0.30  u=0.07 f=0.0(EOF marker)
    Ran myran=new Ran(17);
    byte[]c = new byte[N+1];
    for (i=0;i<N;i++) {
      r=myran.doub();
      if (r < 0.12) c[i]=0;
      else if (r < 0.54) c[i]=1;
      else if (r < 0.63) c[i]=2;
      else if (r < 0.93) c[i]=3;
      else c[i]=4;
View Full Code Here

    tot=NDAT/2;
    for (j=0;j<4;j++) {
      file[j]=new RandomAccessFile(new File(fnames[j]),"rw").getChannel();
    }

    Ran myran = new Ran(17);
    for (i=0;i<nn[2];i++)
      for (j=0;j<nn[1];j++)
        for (k=0;k<nn[0];k++) {
          l=k+j*nn[0]+i*nn[1]*nn[0];
          l=(l<<1);
          data2[l]=data1[l]=2*myran.doub()-1;
          l++;
          data2[l]=data1[l]=2*myran.doub()-1;
        }
    nwrite=NDAT >> 1;
    ByteBuffer bb =  ByteBuffer.allocate(nwrite*8);
    for(int m=0;m<nwrite;m++)bb.putDouble(data1[m]);bb.flip(); file[0].write(bb);bb.clear();
    //file[0].write((char *)&data1[0],nwrite*sizeof(double));
 
View Full Code Here

   

    // Test Nearpoints
    System.out.println("Testing Nearpoints");

    Ran myran=new Ran(17);

    // Create KDtree and Qotree of same Points<2> in 2D
    for (i=0;i<N;i++) {
      pvec[i] = new Point(2);
      pvec[i].x[0]=myran.doub();
      pvec[i].x[1]=myran.doub();
    }

    Nearpoints qo = new Nearpoints(2,pvec);
    KDtree kd = new KDtree(2,pvec);

    int[] kdlist=new int[M];
    Point[] qolist=new Point[M];

    testpt.x[0]=0.6;
    testpt.x[1]=0.7;
    r=0.1;
    nkd=kd.locatenear(testpt,r,kdlist,M);
    nqo=qo.locatenear(testpt,r,qolist,M);

    // See if KDtree and Nearpoints found the same number of
    // neighbors withing radius r
    localflag = (nkd != nqo);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Nearpoints,2D: KDtree found a different number of neighbors inside radius r");
     
    }

    // See if each point from kdlist can be found in qolist
    sbeps=1.e-16;
    if (nkd == nqo) {
      for (i=0;i<nkd;i++) {
        min=1.e99;
        for (j=0;j<nqo;j++) {
          d=dist(kd.ptss[kdlist[i]],qolist[j]);
          if (d < min) min=d;
        }
//        System.out.printf(min);
        localflag = min > sbeps;
        globalflag = globalflag || localflag;
        if (localflag) {
          fail("*** Nearpoints,2D: A point identified by KDtree was not found by Nearpoints");
         
        }
      }
    }

    // Create KDtree and Qotree of same Points<3> in 3D
    Point test3pt=new Point(3);
    Point[] p3vec=new Point[N]
    for (i=0;i<N;i++) {
      p3vec[i] = new Point(3);
      p3vec[i].x[0]=myran.doub();
      p3vec[i].x[1]=myran.doub();
      p3vec[i].x[2]=myran.doub();
    }

    Nearpoints qo3=new Nearpoints(3,p3vec);
    KDtree kd3=new KDtree(3,p3vec);

View Full Code Here

   

    // Test Convexhull
    System.out.println("Testing Convexhull");

    Ran myran = new Ran(17);
    for (i=0;i<N;i++) {
      pvec[i].x[0]=myran.doub();
      pvec[i].x[1]=myran.doub();
    }
    Convexhull cvx=new Convexhull(pvec);

    // Hull should be close to unit square
//    System.out.printf(cvx.nhull);
View Full Code Here

   

    // Test KDtree
    System.out.println("Testing KDtree");

    Ran myran=new Ran(17);

    // Test KDtree in 2D
    for (i=0;i<N;i++) {
      kd2[i] = new Point(2);
      kd2[i].x[0]=myran.doub();
      kd2[i].x[1]=myran.doub();
    }
    KDtree tree2=new KDtree(2,kd2);
   
    // Test locate(Point) method
    Point y=new Point(2);
    int nb;       // number of box containing y
    localflag=false;
    for (i=0;i<M;i++) {
      y.x[0]=myran.doub();
      y.x[1]=myran.doub();
      nb=tree2.locate(y);
//      System.out.printf(nb);
//      System.out.printf(tree2.boxes[nb].lo.x[0] << " %f\n", tree2.boxes[nb].lo.x[1]);
//      System.out.printf(tree2.boxes[nb].hi.x[0] << " %f\n", tree2.boxes[nb].hi.x[1]);
      localflag = localflag || (y.x[0] < tree2.boxes[nb].lo.x[0]);
      localflag = localflag || (y.x[0] > tree2.boxes[nb].hi.x[0]);
      localflag = localflag || (y.x[1] < tree2.boxes[nb].lo.x[1]);
      localflag = localflag || (y.x[1] > tree2.boxes[nb].hi.x[1]);
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** KDtree<2>,locate(Point): The located box does not contain selected point");
       
      }
    }

    // Test locate(int) method
    int n0;
    localflag=false;
    for (i=0;i<M;i++) {
      n0=myran.int32p() % N;
      nb=tree2.locate(n0);
//      System.out.printf(nb);
//      System.out.printf(tree2.boxes[nb].lo.x[0] << " %f\n", tree2.boxes[nb].lo.x[1]);
//      System.out.printf(tree2.boxes[nb].hi.x[0] << " %f\n", tree2.boxes[nb].hi.x[1]);
      localflag = localflag || (kd2[n0].x[0] < tree2.boxes[nb].lo.x[0]);
      localflag = localflag || (kd2[n0].x[0] > tree2.boxes[nb].hi.x[0]);
      localflag = localflag || (kd2[n0].x[1] < tree2.boxes[nb].lo.x[1]);
      localflag = localflag || (kd2[n0].x[1] > tree2.boxes[nb].hi.x[1]);
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** KDtree<2>,locate(int): The located box does not contain selected point");
       
      }
    }

    // Test disti() method
    int n1,n2;
    sbeps=1.e-15;
    localflag=false;
    for (i=0;i<M;i++) {
      n1=myran.int32p() % N;
      n2=myran.int32p() % N;
      double dis=tree2.disti(n1,n2);
//      System.out.printf(dis << " %f\n", sqrt(SQR(kd2[n1].x[0]-kd2[n2].x[0])
//        + SQR(kd2[n1].x[1]-kd2[n2].x[1])));
      if (n1 == n2)
        localflag = localflag || dis < 1.e99;
      else
        localflag = localflag || (dis-sqrt(SQR(kd2[n1].x[0]-kd2[n2].x[0])
          + SQR(kd2[n1].x[1]-kd2[n2].x[1]))) > sbeps;
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** KDtree<2>,disti(): The disti() method gave an incorrect result");
       
      }
    }

    // Test nearest() method
    int j,n3;
    double dis2sq;
    localflag=false;
    for (i=0;i<M;i++) {
      y.x[0]=myran.doub();
      y.x[1]=myran.doub();
      n3=tree2.nearest(y);
      dis2sq=SQR(kd2[n3].x[0]-y.x[0])+SQR(kd2[n3].x[1]-y.x[1]);
      for (j=0;j<N;j++) {
        if (j != n3) localflag = localflag ||
          (SQR(kd2[j].x[0]-y.x[0])+ SQR(kd2[j].x[1]-y.x[1])) < dis2sq;
      }
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** KDtree<2>,nearest(): Exhaustive search found closer point");
       
      }
    }

    // Test nnearest() method
    int n4,n,nfar,K=5;
    boolean test;
    double far;
    int[]nn=new int[K];
    double[] dn=new double[K];
    localflag=false;
    for (i=0;i<M;i++) {
      n4=myran.int32p()%N;
      tree2.nnearest(n4,nn,dn,K);   // Find K nearest Points
      // See if there is anything closer than the furthest
      // of these points, other than the other points in the list nn[]
      far=0.0;
      nfar=0;
      for (j=0;j<K;j++)
        if (dn[j] > far) {
          far=dn[j];
          nfar=nn[j];
        }
      test=false;
      for (j=0;j<N;j++) {
        for (n=0;n<K;n++)
          test = test || (nn[n] == j);
        if (!test)
          localflag = localflag || (tree2.disti(j,n4) < far);
        globalflag = globalflag || localflag;
        if (localflag) {
          fail("*** KDtree<2>,nnearest(): Found a nearer point than the supposed n nearest");
         
        }
      }
    }

    // Test locatenear() method
    int nmax=N/10;
    int[] list=new int[nmax];
    double r=0.1;
    y.x[0]=0.5;
    y.x[1]=0.5;
    int nret=tree2.locatenear(y,r,list,nmax);
    // Check the result by brute force
    int[] list2=new int[nmax];
    int nret2=0;
    for (i=0;i<N;i++) {
      if ((dist(y,kd2[i]) < r) && (nret2 < nmax)) {
        list2[nret2]=i;
        nret2++;
      }
    }

//    System.out.printf(nret << " %f\n", nret2);
    localflag = (nret != nret2);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** KDtree<2>,locatenear(): Found different number of points closer than radius r");
     
    }

    // Make sure list[] and list2[] are the same
    int[] llist=buildVector(list),llist2=buildVector(list2);
    Arrays.sort(llist);
    Arrays.sort(llist2);
    localflag=false;
    for (i=0;i<nret;i++) {
//      System.out.printf(llist[i] << " %f\n", llist2[i]);
      localflag=localflag || (llist[i] != llist2[i]);
    }
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** KDtree<2>,locatenear(): The list of nearby points is not correct");
     
    }

    // Repeat all the tests in 3D
    // Test KDtree in 3D
    for (i=0;i<N;i++) {
      kd3[i] = new Point(3);
      kd3[i].x[0]=myran.doub();
      kd3[i].x[1]=myran.doub();
      kd3[i].x[2]=myran.doub();
    }
    KDtree tree3 = new KDtree(3,kd3);

    // Test locate(Point) method in 3D
    Point yy=new Point(3);
    localflag=false;
    for (i=0;i<M;i++) {
      yy.x[0]=myran.doub();
      yy.x[1]=myran.doub();
      yy.x[2]=myran.doub();
      nb=tree3.locate(yy);
//      System.out.printf(nb);
//      System.out.printf(tree3.boxes[nb].lo.x[0] << " %f\n", tree3.boxes[nb].lo.x[1]
//        << tree3.boxes[nb].lo.x[2]);
//      System.out.printf(tree3.boxes[nb].hi.x[0] << " %f\n", tree3.boxes[nb].hi.x[1]
//        << tree3.boxes[nb].hi.x[2]);
      localflag = localflag || (yy.x[0] < tree3.boxes[nb].lo.x[0]);
      localflag = localflag || (yy.x[0] > tree3.boxes[nb].hi.x[0]);
      localflag = localflag || (yy.x[1] < tree3.boxes[nb].lo.x[1]);
      localflag = localflag || (yy.x[1] > tree3.boxes[nb].hi.x[1]);
      localflag = localflag || (yy.x[2] < tree3.boxes[nb].lo.x[2]);
      localflag = localflag || (yy.x[2] > tree3.boxes[nb].hi.x[2]);
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** KDtree<3>,locate(Point): The located box does not contain selected point");
       
      }
    }

    // Test locate(int) method in 3D
    localflag=false;
    for (i=0;i<M;i++) {
      n0=myran.int32p() % N;
      nb=tree3.locate(n0);
//      System.out.printf(nb);
//      System.out.printf(tree3.boxes[nb].lo.x[0] << " %f\n", tree3.boxes[nb].lo.x[1]
//        tree3.boxes[nb].lo.x[2]);
//      System.out.printf(tree3.boxes[nb].hi.x[0] << " %f\n", tree3.boxes[nb].hi.x[1]
//        tree3.boxes[nb].hi.x[2]);
      localflag = localflag || (kd3[n0].x[0] < tree3.boxes[nb].lo.x[0]);
      localflag = localflag || (kd3[n0].x[0] > tree3.boxes[nb].hi.x[0]);
      localflag = localflag || (kd3[n0].x[1] < tree3.boxes[nb].lo.x[1]);
      localflag = localflag || (kd3[n0].x[1] > tree3.boxes[nb].hi.x[1]);
      localflag = localflag || (kd3[n0].x[2] < tree3.boxes[nb].lo.x[2]);
      localflag = localflag || (kd3[n0].x[2] > tree3.boxes[nb].hi.x[2]);
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** KDtree<3>,locate(int): The located box does not contain selected point");
       
      }
    }

    // Test disti() method in 3D
    sbeps=1.e-15;
    localflag=false;
    for (i=0;i<M;i++) {
      n1=myran.int32p() % N;
      n2=myran.int32p() % N;
      double dis=tree3.disti(n1,n2);
//      System.out.printf(dis << " %f\n", sqrt(SQR(kd3[n1].x[0]-kd3[n2].x[0])
//        + SQR(kd3[n1].x[1]-kd3[n2].x[1])
//        + SQR(kd3[n1].x[2]-kd3[n2].x[2])));
      if (n1 == n2)
        localflag = localflag || dis < 1.e99;
      else
        localflag = localflag || (dis-sqrt(SQR(kd3[n1].x[0]-kd3[n2].x[0])
          + SQR(kd3[n1].x[1]-kd3[n2].x[1])
          + SQR(kd3[n1].x[2]-kd3[n2].x[2]))) > sbeps;
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** KDtree<3>,disti(): The disti() method gave an incorrect result");
       
      }
    }

    // Test nearest() method in 3D
    double dis3sq;
    localflag=false;
    for (i=0;i<M;i++) {
      yy.x[0]=myran.doub();
      yy.x[1]=myran.doub();
      yy.x[2]=myran.doub();
      n3=tree3.nearest(yy);
      dis3sq=SQR(kd3[n3].x[0]-yy.x[0])+SQR(kd3[n3].x[1]-yy.x[1])
        +SQR(kd3[n3].x[2]-yy.x[2]);
      for (j=0;j<N;j++) {
        if (j != n3) localflag = localflag ||
          (SQR(kd3[j].x[0]-yy.x[0]) + SQR(kd3[j].x[1]-yy.x[1])
          + SQR(kd3[j].x[2]-yy.x[2])) < dis3sq;
      }
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** KDtree<3>,nearest(): Exhaustive search found closer point");
       
      }
    }

    // Test nnearest() method in 3D
    localflag=false;
    for (i=0;i<M;i++) {
      n4=myran.int32p() % N;
      tree3.nnearest(n4,nn,dn,K);   // Find K nearest Points
      // See if there is anything closer than the furthest
      // of these points, other than the other points in the list nn[]
      far=0.0;
      nfar=0;
View Full Code Here

   

    // Test Minspantree
    System.out.println("Testing Minspantree");

    Ran myran=new Ran(17);
    for (i=0;i<N;i++) {
      pvec[i].x[0]=myran.doub();
      pvec[i].x[1]=myran.doub();
    }

    Minspantree minspan=new Minspantree(pvec);

      localflag = (minspan.nspan != N-1);
View Full Code Here

    System.out.println("Testing Arithcode");

    // Create a random message in vowellish with character frequencies
    // as given in the book
    // a= 0.12  e=0.42  i=0.09  o=0.30  u=0.07 f=0.0(EOF marker)
    Ran myran=new Ran(17);
    byte[] c = new byte[N+1];
    for (i=0;i<N;i++) {
      r=myran.doub();
      if (r < 0.12) c[i]=0;
      else if (r < 0.54) c[i]=1;
      else if (r < 0.63) c[i]=2;
      else if (r < 0.93) c[i]=3;
      else c[i]=4;
View Full Code Here

TOP

Related Classes of com.nr.ran.Ran

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.