List of usage examples for org.apache.commons.math3.random RandomGenerator nextBytes
void nextBytes(byte[] bytes);
From source file:com.github.rinde.rinsim.core.model.rand.RandomModelTest.java
static void testUnmodifiable(RandomGenerator rng) { boolean fail = false; try {// w w w. j av a 2 s . c o m rng.setSeed(0); } catch (final UnsupportedOperationException e) { fail = true; } assertTrue(fail); fail = false; try { rng.setSeed(new int[] { 0 }); } catch (final UnsupportedOperationException e) { fail = true; } assertTrue(fail); fail = false; try { rng.setSeed(123L); } catch (final UnsupportedOperationException e) { fail = true; } assertTrue(fail); fail = false; rng.nextBoolean(); rng.nextBytes(new byte[] {}); rng.nextDouble(); rng.nextFloat(); rng.nextGaussian(); rng.nextInt(); rng.nextInt(1); rng.nextLong(); }
From source file:com.milaboratory.primitivio.PrimitivIOTest.java
@Test public void testDefaultSerialization1() throws Exception { RandomGenerator rg = new Well19937c(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); PrimitivO po = new PrimitivO(bos); byte[] bytes = new byte[100]; rg.nextBytes(bytes); int[] ints = new int[100]; for (int i = 0; i < ints.length; i++) ints[i] = rg.nextInt(Integer.MAX_VALUE); int cc = 10;// w ww . jav a 2s.com for (int i = 0; i < cc; ++i) { po.writeObject(bytes); po.writeObject(ints); } ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); PrimitivI pi = new PrimitivI(bis); for (int i = 0; i < cc; ++i) { Assert.assertArrayEquals(bytes, pi.readObject(byte[].class)); Assert.assertArrayEquals(ints, pi.readObject(int[].class)); } }