@Override
        protected void produceData(final StreamChannel<ByteBuffer> channel) throws IOException {
            final int chunk = Math.min((int) (remaining < Integer.MAX_VALUE ? remaining : Integer.MAX_VALUE), buffer.remaining());
            for (int i = 0; i < chunk; i++) {
                final byte b = RANGE[(int) (Math.random() * RANGE.length)];
                buffer.put(b);
            }
            remaining -= chunk;

            buffer.flip();
            channel.write(buffer);
            buffer.compact();

            if (remaining <= 0 && buffer.position() == 0) {
                channel.endStream();
            }
        }
The length of the random data to generate.
httpclient5-testing/src/main/java/org/apache/hc/client5/testing/async/AsyncRandomHandler.java