private static int readUnsignedVarintLegacy(ByteBuffer buffer) {
        int value = 0;
        int i = 0;
        int b;
        while (((b = buffer.get()) & 0x80) != 0) {
            value |= (b & 0x7f) << i;
            i += 7;
            if (i > 28)
                throw new IllegalArgumentException();
        }
        value |= b << i;
        return value;
    }
Generates a random int32 number which occupies exactly bytesSet in the variable length encoding for int32

@see {@link #generateRandomLongWithExactBytesSet(int)} for implementation details.
jmh-benchmarks/src/main/java/org/apache/kafka/jmh/util/ByteUtilsBenchmark.java