Examples of MersenneTwister


Examples of cern.jet.random.engine.MersenneTwister

                               + num.format(chiSq(ids.count(id), expected)) + "\t"
                               + prct.format((ids.count(id) - expected) / expected));
            chiSq += chiSq(ids.count(id), expected);
        }
        System.out.println("X^2 = " + chiSq);
        ChiSquare dist = new ChiSquare(df, new MersenneTwister());
        // p-value is ~= prob of seeing this distribution from fair router
        double pValue = 1.0 - dist.cdf(chiSq);
        System.out.println("p-value = " + pValue);
        assertTrue("Non-uniform load distribution detected.", pValue >= 0.05);
    }
View Full Code Here

Examples of de.yaams.extensions.basemap.tiled.util.MersenneTwister

  private final MersenneTwister mt;
  private double ratio = 0.5;

  public RandomBrush(Area shape) {
    super(shape);
    mt = new MersenneTwister(System.currentTimeMillis());
  }
View Full Code Here

Examples of freenet.support.math.MersenneTwister

    checkBlock(buf, true);
  }
 
  public void testEncodeDecodeFullBlock() throws CHKEncodeException, CHKVerifyException, CHKDecodeException, UnsupportedEncodingException, InvalidCompressionCodecException, IOException {
    byte[] fullBlock = new byte[CHKBlock.DATA_LENGTH];
    MersenneTwister random = new MersenneTwister(42);
    for(int i=0;i<10;i++) {
      random.nextBytes(fullBlock);
      checkBlock(fullBlock, false);
      checkBlock(fullBlock, true);
    }
  }
View Full Code Here

Examples of freenet.support.math.MersenneTwister

      checkBlock(s.getBytes("UTF-8"), true);
    }
  }
 
  public void testEncodeDecodeRandomLength() throws CHKEncodeException, CHKVerifyException, CHKDecodeException, UnsupportedEncodingException, InvalidCompressionCodecException, IOException
    MersenneTwister random = new MersenneTwister(42);
    for(int i=0;i<10;i++) {
      byte[] buf = new byte[random.nextInt(CHKBlock.DATA_LENGTH+1)];
      random.nextBytes(buf);
      checkBlock(buf, false);
      checkBlock(buf, true);
    }
  }
View Full Code Here

Examples of freenet.support.math.MersenneTwister

      checkBlock(buf, true);
    }
  }
 
  public void testEncodeDecodeNearlyFullBlock() throws CHKEncodeException, CHKVerifyException, CHKDecodeException, UnsupportedEncodingException, InvalidCompressionCodecException, IOException
    MersenneTwister random = new MersenneTwister(68);
    for(int i=0;i<10;i++) {
      byte[] buf = new byte[CHKBlock.DATA_LENGTH - i];
      random.nextBytes(buf);
      checkBlock(buf, false);
      checkBlock(buf, true);
    }
    for(int i=0;i<10;i++) {
      byte[] buf = new byte[CHKBlock.DATA_LENGTH - (1<<i)];
      random.nextBytes(buf);
      checkBlock(buf, false);
      checkBlock(buf, true);
    }
  }
View Full Code Here

Examples of freenet.support.math.MersenneTwister

    // API NOTE: java.util.Random generates bytes by generating ints, so the stream is
    // reproducible provided that the chunks are always exact multiples of 4 bytes.
    assertTrue(writeStep % 4 == 0);
    assertTrue(readStep % 4 == 0);
    EncryptingIoAdapter a = createAdapter();
    MersenneTwister dataMT = new MersenneTwister(seed);
    for(int written=0;written<size;) {
      int write = Math.min(writeStep, size-written);
      byte[] data = new byte[write];
      dataMT.nextBytes(data);
      a.write(data);
      written += write;
    }
    dataMT = new MersenneTwister(seed);
    a.seek(0);
    byte[] readBuffer = new byte[readStep];
    for(int read=0;read<size;) {
      int toRead = Math.min(readStep, size-read);
      int readBytes = a.read(readBuffer, toRead);
      assertTrue(readBytes > 0);
      byte[] compareBuf = new byte[readBytes];
      dataMT.nextBytes(compareBuf);
      for(int i=0;i<compareBuf.length;i++)
        assertTrue("Byte "+(i+read)+" is wrong for buffered test size="+size+" write="+writeStep+" read="+readStep+" seed="+seed, readBuffer[i] == compareBuf[i]);
      read += readBytes;
    }
    a.close();
View Full Code Here

Examples of freenet.support.math.MersenneTwister

    a.close();
  }

  public void checkLinearBuffered(int size, int writeStep, int readStep, long seed) {
    EncryptingIoAdapter a = createAdapter();
    MersenneTwister dataMT = new MersenneTwister(seed);
    byte[] bigBuffer = new byte[size];
    dataMT.nextBytes(bigBuffer);
    for(int written=0;written<size;) {
      int write = Math.min(writeStep, size-written);
      byte[] data = new byte[write];
      System.arraycopy(bigBuffer,written,data,0,write);
      a.write(data);
View Full Code Here

Examples of freenet.support.math.MersenneTwister

  }

  private void realRun() {
    Random random;
    if(KILL_BLOCKS != 0)
      random = new MersenneTwister();
    else
      random = null;
    Key[] keys = null;
    SendableGet getter = null;
    ClientRequestScheduler sched = null;
View Full Code Here

Examples of freenet.support.math.MersenneTwister

        File dir = new File("bootstrap-pull-test");
        FileUtil.removeAll(dir);
        RandomSource random = NodeStarter.globalTestInit(dir.getPath(), false, LogLevel.ERROR, "", false);
        byte[] seed = new byte[64];
        random.nextBytes(seed);
        MersenneTwister fastRandom = new MersenneTwister(seed);
        File seednodes = new File("seednodes.fref");
        if(!seednodes.exists() || seednodes.length() == 0 || !seednodes.canRead()) {
          System.err.println("Unable to read seednodes.fref, it doesn't exist, or is empty");
          System.exit(EXIT_NO_SEEDNODES);
        }
        File secondInnerDir = new File(dir, Integer.toString(DARKNET_PORT));
        secondInnerDir.mkdir();
        FileInputStream fis = new FileInputStream(seednodes);
        FileUtil.writeTo(fis, new File(secondInnerDir, "seednodes.fref"));
        fis.close();

        // Create the test data
        System.out.println("Creating test data.");
        File dataFile = File.createTempFile("testdata", ".tmp", dir);
        OutputStream os = new FileOutputStream(dataFile);
        byte[] buf = new byte[4096];
        for(long written = 0; written < TEST_SIZE;) {
          fastRandom.nextBytes(buf);
          int toWrite = (int) Math.min(TEST_SIZE - written, buf.length);
          os.write(buf, 0, toWrite);
          written += toWrite;
        }
        os.close();
View Full Code Here

Examples of freenet.support.math.MersenneTwister

   * @return the paded bucket
   */
  public static Bucket pad(Bucket oldBucket, int blockLength, BucketFactory bf, int length) throws IOException {
    byte[] hash = BucketTools.hash(oldBucket);
    Bucket b = bf.makeBucket(blockLength);
    MersenneTwister mt = new MersenneTwister(hash);
    OutputStream os = b.getOutputStreamUnbuffered();
    try {
      BucketTools.copyTo(oldBucket, os, length);
      byte[] buf = new byte[BUFFER_SIZE];
      for(int x=length;x<blockLength;) {
        int remaining = blockLength - x;
        int thisCycle = Math.min(remaining, buf.length);
        mt.nextBytes(buf); // FIXME??
        os.write(buf, 0, thisCycle);
        x += thisCycle;
      }
      os.close();
      os = null;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.