// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeByte(final boolean unsigned, final int size) {
//     if (size <= 0) {
//         throw new IllegalArgumentException("size(" + size + ") <= 0");
//     }
//     if (size > Byte.SIZE) {
//         throw new IllegalArgumentException("invalid size(" + size + ") > " + Byte.SIZE);
//     }
//     if (unsigned && size == Byte.SIZE) {
//         throw new IllegalArgumentException("invalid size(" + size + ") for unsigned byte");
//     }
//     return size;
// }
// 
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeChar(final int size) {
//     if (size <= 0) {
//         throw new IllegalArgumentException("size(" + size + ") <= 0");
//     }
//     if (size > Character.SIZE) {
//         throw new IllegalArgumentException("size(" + size + ") > " + Character.SIZE);
//     }
//     return size;
// }
// 
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeInt(final boolean unsigned, final int size) {
//     if (size <= 0) {
//         throw new IllegalArgumentException("size(" + size + ") <= 0");
//     }
//     if (size > Integer.SIZE) {
//         throw new IllegalArgumentException("invalid size(" + size + ") > " + Integer.SIZE);
//     }
//     if (unsigned && size == Integer.SIZE) {
//         throw new IllegalArgumentException("invalid size(" + size + ") for unsigned integer");
//     }
//     return size;
// }
// 
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeLong(final boolean unsigned, final int size) {
//     if (size <= 0) {
//         throw new IllegalArgumentException("size(" + size + ") <= 0");
//     }
//     if (size > Long.SIZE) {
//         throw new IllegalArgumentException("invalid size(" + size + ") > " + Long.SIZE);
//     }
//     if (unsigned && size == Long.SIZE) {
//         throw new IllegalArgumentException("invalid size(" + size + ") for unsigned long");
//     }
//     return size;
// }
// 
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeShort(final boolean unsigned, final int size) {
//     if (size <= 0) {
//         throw new IllegalArgumentException("size(" + size + ") <= 0");
//     }
//     if (size > Short.SIZE) {
//         throw new IllegalArgumentException("invalid size(" + size + ") > " + Short.SIZE);
//     }
//     if (unsigned && size == Short.SIZE) {
//         throw new IllegalArgumentException("invalid size(" + size + ") for unsigned short");
//     }
//     return size;
// }


import lombok.extern.slf4j.Slf4j;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeByte;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeChar;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeInt;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeLong;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeShort;
import static java.util.concurrent.ThreadLocalRandom.current;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
        final byte value;
        if (unsigned) {
            value = (byte) (current().nextInt() >>> (Integer.SIZE - size));
            assertTrue(value >= 0);
        } else {
            value = (byte) (current().nextInt() >> (Integer.SIZE - size));
            assertEquals(value >> size, value >= 0 ? 0 : -1);
        }
        return value;
    }

    // ----------------------------------------------------------------------------------------------------------- short
    static int randomSizeForShort(final boolean unsigned) {
        return requireValidSizeShort(unsigned, current().nextInt(1, Short.SIZE + (unsigned ? 0 : 1)));
    }

    static short randomValueForShort(final boolean unsigned, final int size) {
        final short value;
        if (unsigned) {
            value = (short) (current().nextInt() >>> (Integer.SIZE - size));
            assertTrue(value >= 0);
        } else {
            value = (short) (current().nextInt() >> (Integer.SIZE - size));
            assertEquals(value >> size, value >= 0 ? 0 : -1);
        }
        return value;
    }

    // ------------------------------------------------------------------------------------------------------------- int
    static int randomSizeForInt(final boolean unsigned) {
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeByte(final boolean unsigned, final int size) {
//     if (size <= 0) {
//         throw new IllegalArgumentException("size(" + size + ") <= 0");
//     }
//     if (size > Byte.SIZE) {
//         throw new IllegalArgumentException("invalid size(" + size + ") > " + Byte.SIZE);
//     }
//     if (unsigned && size == Byte.SIZE) {
//         throw new IllegalArgumentException("invalid size(" + size + ") for unsigned byte");
//     }
//     return size;
// }
// 
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeChar(final int size) {
//     if (size <= 0) {
//         throw new IllegalArgumentException("size(" + size + ") <= 0");
//     }
//     if (size > Character.SIZE) {
//         throw new IllegalArgumentException("size(" + size + ") > " + Character.SIZE);
//     }
//     return size;
// }
// 
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeInt(final boolean unsigned, final int size) {
//     if (size <= 0) {
//         throw new IllegalArgumentException("size(" + size + ") <= 0");
//     }
//     if (size > Integer.SIZE) {
//         throw new IllegalArgumentException("invalid size(" + size + ") > " + Integer.SIZE);
//     }
//     if (unsigned && size == Integer.SIZE) {
//         throw new IllegalArgumentException("invalid size(" + size + ") for unsigned integer");
//     }
//     return size;
// }
// 
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeLong(final boolean unsigned, final int size) {
//     if (size <= 0) {
//         throw new IllegalArgumentException("size(" + size + ") <= 0");
//     }
//     if (size > Long.SIZE) {
//         throw new IllegalArgumentException("invalid size(" + size + ") > " + Long.SIZE);
//     }
//     if (unsigned && size == Long.SIZE) {
//         throw new IllegalArgumentException("invalid size(" + size + ") for unsigned long");
//     }
//     return size;
// }
// 
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeShort(final boolean unsigned, final int size) {
//     if (size <= 0) {
//         throw new IllegalArgumentException("size(" + size + ") <= 0");
//     }
//     if (size > Short.SIZE) {
//         throw new IllegalArgumentException("invalid size(" + size + ") > " + Short.SIZE);
//     }
//     if (unsigned && size == Short.SIZE) {
//         throw new IllegalArgumentException("invalid size(" + size + ") for unsigned short");
//     }
//     return size;
// }


// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
import lombok.extern.slf4j.Slf4j;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeByte;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeChar;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeInt;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeLong;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeShort;
import static java.util.concurrent.ThreadLocalRandom.current;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

        final byte value;
        if (unsigned) {
            value = (byte) (current().nextInt() >>> (Integer.SIZE - size));
            assertTrue(value >= 0);
        } else {
            value = (byte) (current().nextInt() >> (Integer.SIZE - size));
            assertEquals(value >> size, value >= 0 ? 0 : -1);
        }
        return value;
    }

    // ----------------------------------------------------------------------------------------------------------- short
    static int randomSizeForShort(final boolean unsigned) {
        return requireValidSizeShort(unsigned, current().nextInt(1, Short.SIZE + (unsigned ? 0 : 1)));
    }

    static short randomValueForShort(final boolean unsigned, final int size) {
        final short value;
        if (unsigned) {
            value = (short) (current().nextInt() >>> (Integer.SIZE - size));
            assertTrue(value >= 0);
        } else {
            value = (short) (current().nextInt() >> (Integer.SIZE - size));
            assertEquals(value >> size, value >= 0 ? 0 : -1);
        }
        return value;
    }

    // ------------------------------------------------------------------------------------------------------------- int
    static int randomSizeForInt(final boolean unsigned) {
        return requireValidSizeInt(unsigned, current().nextInt(1, Integer.SIZE + (unsigned ? 0 : 1)));