Example usage for java.util Random nextBoolean

List of usage examples for java.util Random nextBoolean

Introduction

In this page you can find the example usage for java.util Random nextBoolean.

Prototype

public boolean nextBoolean() 

Source Link

Document

Returns the next pseudorandom, uniformly distributed boolean value from this random number generator's sequence.

Usage

From source file:cytoscape.render.immed.GraphGraphicsTest.java

private long drawCurrentFull(Random rand) {
    final float nodeSizeFactor = 50f;
    float size = (float) canvasSize;

    long begin = System.nanoTime();
    for (int i = 0; i < numNodes; i++) {
        float x = rand.nextFloat() * (rand.nextBoolean() ? size : -size);
        float y = rand.nextFloat() * (rand.nextBoolean() ? size : -size);
        currentGraphGraphics.drawNodeFull((byte) (i % (int) GraphGraphics.s_last_shape), x, y,
                (x + (rand.nextFloat() * nodeSizeFactor)), (y + (rand.nextFloat() * nodeSizeFactor)),
                Color.blue, 1.0f + (i % 10), Color.yellow);
    }/*from   w w w. j av a2 s  . c om*/
    long end = System.nanoTime();
    long nodeDur = end - begin;

    BasicStroke edgeStroke = new BasicStroke(1f);

    begin = System.nanoTime();
    for (int i = 0; i < numEdges; i++) {
        currentGraphGraphics.drawEdgeFull((byte) ((i % 7) - 8), rand.nextFloat() * (20f), Color.red,
                (byte) ((i % 7) - 8), rand.nextFloat() * (20f), Color.orange,
                rand.nextFloat() * (rand.nextBoolean() ? size : -size),
                rand.nextFloat() * (rand.nextBoolean() ? size : -size), currentGraphGraphics.m_noAnchors,
                rand.nextFloat() * (rand.nextBoolean() ? size : -size),
                rand.nextFloat() * (rand.nextBoolean() ? size : -size), 1f, edgeStroke, Color.green);
    }
    end = System.nanoTime();
    long duration = (end - begin) + nodeDur;

    //      try {
    //         ImageIO.write(image,"PNG",new File("/tmp/homer-current-" + rand.nextInt(100) + ".png"));
    //      } catch (IOException ioe) { ioe.printStackTrace(); }
    return duration;
}

From source file:cytoscape.render.immed.GraphGraphicsTest.java

private long drawOldFull(Random rand) {
    final float nodeSizeFactor = 50f;
    float size = (float) canvasSize;

    long begin = System.nanoTime();
    for (int i = 0; i < numNodes; i++) {
        float x = rand.nextFloat() * (rand.nextBoolean() ? size : -size);
        float y = rand.nextFloat() * (rand.nextBoolean() ? size : -size);
        oldGraphGraphics.drawNodeFull((byte) (i % (int) OldGraphGraphics.s_last_shape), x, y,
                (x + (rand.nextFloat() * nodeSizeFactor)), (y + (rand.nextFloat() * nodeSizeFactor)),
                Color.blue, 1.0f + (i % 10), Color.yellow);
    }/*ww  w  .  j a  v  a 2 s. c  o m*/
    long end = System.nanoTime();
    long nodeDur = end - begin;

    BasicStroke edgeStroke = new BasicStroke(1f);

    begin = System.nanoTime();
    for (int i = 0; i < numEdges; i++) {
        oldGraphGraphics.drawEdgeFull((byte) ((i % 7) - 8), rand.nextFloat() * (20f), Color.red,
                (byte) ((i % 7) - 8), rand.nextFloat() * (20f), Color.orange,
                rand.nextFloat() * (rand.nextBoolean() ? size : -size),
                rand.nextFloat() * (rand.nextBoolean() ? size : -size), oldGraphGraphics.m_noAnchors,
                rand.nextFloat() * (rand.nextBoolean() ? size : -size),
                rand.nextFloat() * (rand.nextBoolean() ? size : -size), 1f, Color.green, 0f);
    }
    end = System.nanoTime();

    long duration = (end - begin) + nodeDur;

    //      try {
    //         ImageIO.write(image,"PNG",new File("/tmp/homer-old-" + rand.nextInt(100) + ".png"));
    //      } catch (IOException ioe) { ioe.printStackTrace(); }
    return duration;
}

From source file:org.cytoscape.graph.render.immed.GraphGraphicsTest.java

private long drawOldFull(Random rand) {
    final float nodeSizeFactor = 50f;
    float size = (float) canvasSize;

    long begin = System.nanoTime();
    for (int i = 0; i < numNodes; i++) {
        float x = rand.nextFloat() * (rand.nextBoolean() ? size : -size);
        float y = rand.nextFloat() * (rand.nextBoolean() ? size : -size);
        oldGraphGraphics.drawNodeFull((byte) (i % (int) OldGraphGraphics.s_last_shape), x, y,
                (x + (rand.nextFloat() * nodeSizeFactor)), (y + (rand.nextFloat() * nodeSizeFactor)),
                Color.blue, 1.0f + (i % 10), Color.yellow);
    }/*from   w  w  w . j  a v  a 2  s.  co  m*/
    long end = System.nanoTime();
    long nodeDur = end - begin;

    BasicStroke edgeStroke = new BasicStroke(1f);

    begin = System.nanoTime();
    for (int i = 0; i < numEdges; i++) {
        oldGraphGraphics.drawEdgeFull((byte) ((i % 7) - 8), rand.nextFloat() * (20f), Color.red,
                (byte) ((i % 7) - 8), rand.nextFloat() * (20f), Color.orange,
                rand.nextFloat() * (rand.nextBoolean() ? size : -size),
                rand.nextFloat() * (rand.nextBoolean() ? size : -size), oldGraphGraphics.m_noAnchors,
                rand.nextFloat() * (rand.nextBoolean() ? size : -size),
                rand.nextFloat() * (rand.nextBoolean() ? size : -size), 1f, Color.green, 0f);
    }
    end = System.nanoTime();

    long duration = (end - begin) + nodeDur;
    return duration;
}

From source file:org.cytoscape.graph.render.immed.GraphGraphicsTest.java

private long drawCurrentFull(Random rand) {
    final float nodeSizeFactor = 50f;
    float size = (float) canvasSize;

    long begin = System.nanoTime();
    for (int i = 0; i < numNodes; i++) {
        float x = rand.nextFloat() * (rand.nextBoolean() ? size : -size);
        float y = rand.nextFloat() * (rand.nextBoolean() ? size : -size);
        currentGraphGraphics.drawNodeFull((byte) (i % (int) GraphGraphics.s_last_shape), x, y,
                (x + (rand.nextFloat() * nodeSizeFactor)), (y + (rand.nextFloat() * nodeSizeFactor)),
                Color.blue, 1.0f + (i % 10), null, Color.yellow);
    }/*from w  ww  .j av  a2s  .c om*/
    long end = System.nanoTime();
    long nodeDur = end - begin;

    BasicStroke edgeStroke = new BasicStroke(1f);

    begin = System.nanoTime();
    for (int i = 0; i < numEdges; i++) {
        currentGraphGraphics.drawEdgeFull((byte) ((i % 7) - 8), rand.nextFloat() * (20f), Color.red,
                (byte) ((i % 7) - 8), rand.nextFloat() * (20f), Color.orange,
                rand.nextFloat() * (rand.nextBoolean() ? size : -size),
                rand.nextFloat() * (rand.nextBoolean() ? size : -size), currentGraphGraphics.m_noAnchors,
                rand.nextFloat() * (rand.nextBoolean() ? size : -size),
                rand.nextFloat() * (rand.nextBoolean() ? size : -size), 1f, edgeStroke, Color.green);
    }
    end = System.nanoTime();
    long duration = (end - begin) + nodeDur;

    //      try {
    //         ImageIO.write(image,"PNG",new File("/tmp/homer-current-" + rand.nextInt(100) + ".png"));
    //      } catch (IOException ioe) { ioe.printStackTrace(); }
    return duration;
}

From source file:org.apache.jackrabbit.core.data.DataStoreTest.java

InputStream readInputStreamRandomly(InputStream in, Random random) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    byte[] buffer = new byte[8000];
    while (true) {
        if (random.nextBoolean()) {
            int x = in.read();
            if (x < 0) {
                break;
            }//w  w w .  j  a  v a 2  s .  c  o m
            out.write(x);
        } else {
            if (random.nextBoolean()) {
                int l = in.read(buffer);
                if (l < 0) {
                    break;
                }
                out.write(buffer, 0, l);
            } else {
                int offset = random.nextInt(buffer.length / 2);
                int len = random.nextInt(buffer.length / 2);
                int l = in.read(buffer, offset, len);
                if (l < 0) {
                    break;
                }
                out.write(buffer, offset, l);
            }
        }
    }
    in.close();
    return new ByteArrayInputStream(out.toByteArray());
}

From source file:org.sonar.db.DbSessionImplTest.java

@Test
public void all_methods_to_wrapped_SqlSession() {
    Random random = new Random();
    boolean randomBoolean = random.nextBoolean();
    int randomInt = random.nextInt(200);
    String randomStatement = randomAlphabetic(10);
    Object randomParameter = new Object();
    Cursor<Object> mockCursor = mock(Cursor.class);
    RowBounds rowBounds = new RowBounds();
    Object randomObject = new Object();
    List<Object> randomList = new ArrayList<>();
    Map<Object, Object> randomMap = new HashMap<>();
    String randomMapKey = randomAlphabetic(10);
    ResultHandler randomResultHandler = resultContext -> {
        // don't care
    };//from www . jav  a 2s .c  om
    List<BatchResult> randomBatchResults = new ArrayList<>();
    Configuration randomConfiguration = new Configuration();

    verifyDelegation(DbSessionImpl::commit, s -> verify(s).commit());
    verifyDelegation(t -> t.commit(randomBoolean), s -> verify(s).commit(randomBoolean));

    verifyDelegation(sqlSession -> when(sqlSession.selectCursor(randomStatement)).thenReturn(mockCursor),
            dbSession -> dbSession.selectCursor(randomStatement), sqlSession -> {
                verify(sqlSession).selectCursor(randomStatement);
                return mockCursor;
            });
    verifyDelegation(
            sqlSession -> when(sqlSession.selectCursor(randomStatement, randomParameter))
                    .thenReturn(mockCursor),
            dbSession -> dbSession.selectCursor(randomStatement, randomParameter), sqlSession -> {
                verify(sqlSessionMock).selectCursor(randomStatement, randomParameter);
                return mockCursor;
            });
    verifyDelegation(
            sqlSession -> when(sqlSession.selectCursor(randomStatement, randomParameter, rowBounds))
                    .thenReturn(mockCursor),
            dbSession -> dbSession.selectCursor(randomStatement, randomParameter, rowBounds), sqlSession -> {
                verify(sqlSessionMock).selectCursor(randomStatement, randomParameter, rowBounds);
                return mockCursor;
            });

    verifyDelegation(sqlSession -> when(sqlSession.selectOne(randomStatement)).thenReturn(randomObject),
            dbSession -> dbSession.selectOne(randomStatement), sqlSession -> {
                verify(sqlSession).selectOne(randomStatement);
                return randomObject;
            });
    verifyDelegation(
            sqlSession -> when(sqlSession.selectOne(randomStatement, randomParameter)).thenReturn(randomObject),
            dbSession -> dbSession.selectOne(randomStatement, randomParameter), sqlSession -> {
                verify(sqlSessionMock).selectOne(randomStatement, randomParameter);
                return randomObject;
            });

    verifyDelegation(sqlSession -> when(sqlSession.selectList(randomStatement)).thenReturn(randomList),
            dbSession -> dbSession.selectList(randomStatement), sqlSession -> {
                verify(sqlSession).selectList(randomStatement);
                return randomList;
            });
    verifyDelegation(
            sqlSession -> when(sqlSession.selectList(randomStatement, randomParameter)).thenReturn(randomList),
            dbSession -> dbSession.selectList(randomStatement, randomParameter), sqlSession -> {
                verify(sqlSessionMock).selectList(randomStatement, randomParameter);
                return randomList;
            });
    verifyDelegation(
            sqlSession -> when(sqlSession.selectList(randomStatement, randomParameter, rowBounds))
                    .thenReturn(randomList),
            dbSession -> dbSession.selectList(randomStatement, randomParameter, rowBounds), sqlSession -> {
                verify(sqlSessionMock).selectList(randomStatement, randomParameter, rowBounds);
                return randomList;
            });

    verifyDelegation(
            sqlSession -> when(sqlSession.selectMap(randomStatement, randomMapKey)).thenReturn(randomMap),
            dbSession -> dbSession.selectMap(randomStatement, randomMapKey), sqlSession -> {
                verify(sqlSession).selectMap(randomStatement, randomMapKey);
                return randomMap;
            });
    verifyDelegation(
            sqlSession -> when(sqlSession.selectMap(randomStatement, randomParameter, randomMapKey))
                    .thenReturn(randomMap),
            dbSession -> dbSession.selectMap(randomStatement, randomParameter, randomMapKey), sqlSession -> {
                verify(sqlSessionMock).selectMap(randomStatement, randomParameter, randomMapKey);
                return randomMap;
            });
    verifyDelegation(
            sqlSession -> when(sqlSession.selectMap(randomStatement, randomParameter, randomMapKey, rowBounds))
                    .thenReturn(randomMap),
            dbSession -> dbSession.selectMap(randomStatement, randomParameter, randomMapKey, rowBounds),
            sqlSession -> {
                verify(sqlSessionMock).selectMap(randomStatement, randomParameter, randomMapKey, rowBounds);
                return randomMap;
            });

    verifyDelegation(dbSession -> dbSession.select(randomStatement, randomResultHandler),
            sqlSession -> verify(sqlSessionMock).select(randomStatement, randomResultHandler));
    verifyDelegation(dbSession -> dbSession.select(randomStatement, randomParameter, randomResultHandler),
            sqlSession -> verify(sqlSession).select(randomStatement, randomParameter, randomResultHandler));
    verifyDelegation(
            dbSession -> dbSession.select(randomStatement, randomParameter, rowBounds, randomResultHandler),
            sqlSession -> verify(sqlSessionMock).select(randomStatement, randomParameter, rowBounds,
                    randomResultHandler));

    verifyDelegation(sqlSession -> when(sqlSession.insert(randomStatement)).thenReturn(randomInt),
            dbSession -> dbSession.insert(randomStatement), sqlSession -> {
                verify(sqlSession).insert(randomStatement);
                return randomInt;
            });
    verifyDelegation(
            sqlSession -> when(sqlSession.insert(randomStatement, randomParameter)).thenReturn(randomInt),
            dbSession -> dbSession.insert(randomStatement, randomParameter), sqlSession -> {
                verify(sqlSessionMock).insert(randomStatement, randomParameter);
                return randomInt;
            });

    verifyDelegation(sqlSession -> when(sqlSession.update(randomStatement)).thenReturn(randomInt),
            dbSession -> dbSession.update(randomStatement), sqlSession -> {
                verify(sqlSession).update(randomStatement);
                return randomInt;
            });
    verifyDelegation(
            sqlSession -> when(sqlSession.update(randomStatement, randomParameter)).thenReturn(randomInt),
            dbSession -> dbSession.update(randomStatement, randomParameter), sqlSession -> {
                verify(sqlSessionMock).update(randomStatement, randomParameter);
                return randomInt;
            });

    verifyDelegation(sqlSession -> when(sqlSession.delete(randomStatement)).thenReturn(randomInt),
            dbSession -> dbSession.delete(randomStatement), sqlSession -> {
                verify(sqlSession).delete(randomStatement);
                return randomInt;
            });
    verifyDelegation(
            sqlSession -> when(sqlSession.delete(randomStatement, randomParameter)).thenReturn(randomInt),
            dbSession -> dbSession.delete(randomStatement, randomParameter), sqlSession -> {
                verify(sqlSessionMock).delete(randomStatement, randomParameter);
                return randomInt;
            });

    verifyDelegation(DbSessionImpl::rollback, s -> verify(s).rollback());
    verifyDelegation(t -> t.rollback(randomBoolean), s -> verify(s).rollback(randomBoolean));

    verifyDelegation(sqlSession -> when(sqlSession.flushStatements()).thenReturn(randomBatchResults),
            DbSessionImpl::flushStatements, sqlSession -> {
                verify(sqlSession).flushStatements();
                return randomBatchResults;
            });

    verifyDelegation(DbSessionImpl::close, s -> verify(s).close());

    verifyDelegation(DbSessionImpl::clearCache, s -> verify(s).clearCache());

    verifyDelegation(sqlSession -> when(sqlSession.getConfiguration()).thenReturn(randomConfiguration),
            DbSessionImpl::getConfiguration, sqlSession -> {
                verify(sqlSession).getConfiguration();
                return randomConfiguration;
            });

    verifyDelegation(
            sqlSession -> when(sqlSession.getMapper(DbSessionImplTest.class))
                    .thenReturn(DbSessionImplTest.this),
            dbSession -> dbSession.getMapper(DbSessionImplTest.class), sqlSession -> {
                verify(sqlSession).getMapper(DbSessionImplTest.class);
                return DbSessionImplTest.this;
            });

    verifyDelegation(DbSessionImpl::getConnection, s -> verify(s).getConnection());
}

From source file:com.mapr.synth.samplers.VectorSamplerTest.java

@Test
public void testVector() throws IOException {
    SchemaSampler s = new SchemaSampler(
            Resources.asCharSource(Resources.getResource("schema029.json"), Charsets.UTF_8).read());
    for (int i = 0; i < 10; i++) {
        JsonNode data = s.sample();/*  w w  w. ja  v  a2s . c o  m*/
        /*
        {
        "class": "vector",
        "name": "prices",
        "mean": 4.65,
        "sd": 0.01,
        "length": 10000,
        "transform": "exp",
        "seed": 1,
        },
        */
        JsonNode v = data.get("prices");
        assertTrue(v.isArray());
        assertEquals(10000, v.size());
        double[] v1 = new double[10000];
        double[] v2 = new double[10000];
        for (int j = 0; j < 10000; j++) {
            v1[j] = v.get(j).asDouble();
            v2[j] = Math.log(v1[j]);
        }
        assertEquals(100, median(v1), 0.03);
        assertEquals(100, mean(v1), 0.05);
        assertEquals(Math.log(100), mean(v2), 0.001);
        assertEquals(0.01, sd(v2), 0.0003);
        assertTrue(isNormal(v2, Math.log(100), 0.01));

        /*
        {
        "class": "vector",
        "name": "zero",
        "mean": 0,
        "sd": 10,
        "length": 10000,
        "seed": 2
        },
        */
        v = data.get("zero");
        assertTrue(v.isArray());
        for (int j = 0; j < 10000; j++) {
            v1[j] = v.get(j).asDouble();
        }
        assertEquals(0, mean(v1), 0.3);
        assertEquals(10, sd(v1), 0.2);
        assertTrue(isNormal(v1, 0, 10));
        /*
        {
        "class": "vector",
        "name": "clipped",
        "mean": 0,
        "sd": 10,
        "length": 10000,
        "max": 0,
        "seed": 3
        },
        */
        v = data.get("clipped");
        assertTrue(v.isArray());
        Random rand = new Random();
        for (int j = 0; j < 10000; j++) {
            v1[j] = v.get(j).asDouble();
            assertTrue(v1[j] <= 0);
            v1[j] = v1[j] * (rand.nextBoolean() ? 1 : -1);
        }
        assertEquals(0, mean(v1), 0.3);
        assertEquals(10, sd(v1), 0.3);
        assertTrue(isNormal(v1, 0, 10));

        /*
        {
        "class": "vector",
        "name": "ten",
        "min": 1,
        "max": 10,
        "length": 20000,
        "transform": "log",
        "seed": 4
        }
        ]
                */
        v = data.get("ten");
        assertTrue(v.isArray());
        for (int j = 0; j < 10000; j++) {
            v1[j] = v.get(j).asDouble();
            v2[j] = Math.exp(v1[j]);
            assertTrue(v1[j] >= 1);
            assertTrue(v1[j] <= 10);
        }
        assertTrue(isUniform(v2, Math.exp(1), Math.exp(10)));

        v = data.get("coarse");
        assertTrue(v.isArray());
        for (int j = 0; j < 10000; j++) {
            double x = v.get(j).asDouble();
            assertTrue(x >= 1);
            assertTrue(x <= 10);
            assertEquals(Math.rint(x / 0.1) * 0.1, x, 1e-10);
        }
    }
}

From source file:org.lathanh.android.mvp.demo.presenter.PresenterDemo_Fragment.java

/**
 * Starts a task to "load data."/*from  w  w w  .jav  a 2 s .  c  o  m*/
 *
 * The data is a heterogeneous list of {@link PresenterDemo_RedPresenter Red}
 * and {@link PresenterDemo_GreenPresenter Green} items, which have slightly
 * different visual and onLongClick behavior.
 */
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final long debugLoadStartTime = System.currentTimeMillis();
    new AsyncTask<Void, Void, List>() {

        private PresenterDemo_GreenPresenter greenPresenter;
        private PresenterDemo_RedPresenter redPresenter;

        @Override
        protected List doInBackground(Void... params) {
            //-- "Load" data
            Random random = new Random(0xABCDEF); // same "randomness" every run
            List dataModels = new ArrayList(NUM_LIST_ELEMENTS);
            for (int i = 0; i < NUM_LIST_ELEMENTS; i++) {
                int delayForItem = 6 + random.nextInt(11);
                if (random.nextBoolean()) {
                    // green
                    dataModels.add(new GreenAdaptableViewModel(i, delayForItem, new Date()));
                } else {
                    // red
                    dataModels.add(new RedAdaptableViewModel(i, delayForItem, System.currentTimeMillis()));
                }
            }

            //-- Also prepare the Presenters for this data
            greenPresenter = new PresenterDemo_GreenPresenter();
            redPresenter = new PresenterDemo_RedPresenter();

            return dataModels;
        }

        @Override
        protected void onPostExecute(List list) {
            //-- Create the BindingAdapter and add the Presenters to it
            BindingAdapter bindingAdapter = new BindingAdapter(LayoutInflater.from(getContext()), list);
            bindingAdapter.addPresenter(greenPresenter.getLayoutId(), greenPresenter, greenPresenter,
                    greenPresenter);
            bindingAdapter.addPresenter(redPresenter.getLayoutId(), redPresenter, redPresenter, redPresenter);

            RecyclerView recyclerView = (RecyclerView) getActivity().findViewById(R.id.recycler_view);
            recyclerView.setAdapter(bindingAdapter);

            //-- Update view to show list
            getActivity().findViewById(R.id.loadingView).setVisibility(View.GONE);
            recyclerView.setVisibility(View.VISIBLE);

            long debugElapsedMs = System.currentTimeMillis() - debugLoadStartTime;
            Toast.makeText(getActivity(), "Load completed in " + debugElapsedMs + "ms", Toast.LENGTH_SHORT)
                    .show();
        }
    }.execute();
}

From source file:org.apache.hadoop.hbase.io.encoding.TestChangingEncoding.java

@Test
public void testCrazyRandomChanges() throws Exception {
    prepareTest("RandomChanges");
    Random rand = new Random(2934298742974297L);
    for (int i = 0; i < 20; ++i) {
        int encodingOrdinal = rand.nextInt(DataBlockEncoding.values().length);
        DataBlockEncoding encoding = DataBlockEncoding.values()[encodingOrdinal];
        setEncodingConf(encoding, rand.nextBoolean());
        writeSomeNewData();//www  . j ava2 s.  c  o  m
        verifyAllData();
    }
}

From source file:org.apache.hadoop.io.TestArrayOutputStream.java

private void runComparison(ArrayOutputStream aos, DataOutputStream dos, ByteArrayOutputStream bos)
        throws IOException {
    Random r = new Random();
    // byte//from   w w  w  .jav  a  2s.  com
    int b = r.nextInt(128);
    aos.write(b);
    dos.write(b);

    // byte[]
    byte[] bytes = new byte[10];
    r.nextBytes(bytes);
    aos.write(bytes, 0, 10);
    dos.write(bytes, 0, 10);

    // Byte
    aos.writeByte(b);
    dos.writeByte(b);

    // boolean
    boolean bool = r.nextBoolean();
    aos.writeBoolean(bool);
    dos.writeBoolean(bool);

    // short
    short s = (short) r.nextInt();
    aos.writeShort(s);
    dos.writeShort(s);

    // char
    int c = r.nextInt();
    aos.writeChar(c);
    dos.writeChar(c);

    // int
    int i = r.nextInt();
    aos.writeInt(i);
    dos.writeInt(i);

    // long
    long l = r.nextLong();
    aos.writeLong(l);
    dos.writeLong(l);

    // float
    float f = r.nextFloat();
    aos.writeFloat(f);
    dos.writeFloat(f);

    // double
    double d = r.nextDouble();
    aos.writeDouble(d);
    dos.writeDouble(d);

    // strings
    String str = RandomStringUtils.random(20);
    aos.writeBytes(str);
    aos.writeChars(str);
    aos.writeUTF(str);
    dos.writeBytes(str);
    dos.writeChars(str);
    dos.writeUTF(str);

    byte[] expected = bos.toByteArray();
    assertEquals(expected.length, aos.size());

    byte[] actual = new byte[aos.size()];
    System.arraycopy(aos.getBytes(), 0, actual, 0, actual.length);
    // serialized bytes should be the same
    assertTrue(Arrays.equals(expected, actual));
}